Submission #3000239
Source Code Expand
// ref: https://arc068.contest.atcoder.jp/submissions/3000198
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8] = { 0,0,-1,1,1,1,-1,-1 };
int dy[8] = { -1,1,0,0,1,-1,1,-1 };
const int SIZE = 300050;
//ここまでテンプレ
//↓Binary Indexed Tree
struct BIT {
private:
int n;
vector<int> node;
public:
//N要素のBITを作り、すべて0で初期化する
//1-indexedであることに注意!!
BIT(int N) {
node.resize(N + 1, 0);
n = N;
}
//ノードiまでの和を計算する
int sum(int i) {
if (!i)
return 0;
return node[i] + sum(i - (i&-i));
}
//ノードiにxを足す
void add(int i, int x) {
if (i > n)
return;
node[i] += x;
add(i + (i&-i), x);
}
};
//↑Binary Indexed Tree
int main() {
int N, M;
cin >> N >> M;
//x=l,y=r
//クエリ<x,0:区間,1:質問,y>
vector<tint> Q;
Q.reserve(2*M*log(M) + 10);
//クエリに区間を入れる
for (int i = 0; i < N; i++) {
int l, r;
cin >> l >> r;
Q.push_back(mt(l, 0, r));
}
//クエリに質問を入れていく
for (int i = 1; i <= M; i++) {
for (int j = i; j <= M; j += i) {
int a = j - i, b = j;
//すでに入れてたら入れない
Q.push_back(mt(b, 1, b));
Q.push_back(mt(a, 1, b));
}
}
sort(Q.begin(), Q.end());
Q.erase(std::unique(Q.begin(), Q.end()), Q.end());
//BIT
BIT B(M + 2);
//クエリを処理する
vector<unordered_map<int, int> > pam(M + 2);
for (const tint& T : Q) {
int a, b, c;
tie(a, c, b) = T;
//区間クエリなら、区間を追加する
if (c == 0) {
//S.update(b,S.getsum(b,b+1)+1);
B.add(b + 1, 1);
}
//質問クエリなら、質問に答える
else {
//pam[mp(a,b)]=S.getsum(b,M+1);
pam[a][b] = B.sum(M + 1) - B.sum(b);
}
}
/*
for(pair<pint,int> P:pam)
cout<<P.first.first<<" "<<P.first.second<<" "<<P.second<<endl;
*/
//答えを求める
for (int i = 1; i <= M; i++) {
int ans = 0;
for (int j = i; j <= M; j += i) {
int a = j - i, b = j;
ans += pam[b][b] - pam[a][b];
}
cout << ans << endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Snuke Line |
User |
kurenaif |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2984 Byte |
Status |
WA |
Exec Time |
947 ms |
Memory |
95128 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_example_01.txt, 00_example_02.txt |
All |
00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt |
Case Name |
Status |
Exec Time |
Memory |
00_example_01.txt |
AC |
14 ms |
896 KB |
00_example_02.txt |
WA |
1 ms |
256 KB |
01.txt |
WA |
1 ms |
256 KB |
02.txt |
WA |
2 ms |
384 KB |
03.txt |
WA |
2 ms |
384 KB |
04.txt |
WA |
1 ms |
256 KB |
05.txt |
AC |
5 ms |
744 KB |
06.txt |
AC |
5 ms |
744 KB |
07.txt |
WA |
1 ms |
256 KB |
08.txt |
AC |
3 ms |
512 KB |
09.txt |
WA |
2 ms |
256 KB |
10.txt |
AC |
2 ms |
256 KB |
11.txt |
WA |
416 ms |
38748 KB |
12.txt |
WA |
906 ms |
94704 KB |
13.txt |
WA |
198 ms |
9156 KB |
14.txt |
WA |
167 ms |
5696 KB |
15.txt |
WA |
167 ms |
5624 KB |
16.txt |
WA |
346 ms |
29344 KB |
17.txt |
WA |
882 ms |
90728 KB |
18.txt |
WA |
158 ms |
5556 KB |
19.txt |
WA |
909 ms |
94104 KB |
20.txt |
WA |
913 ms |
94616 KB |
21.txt |
WA |
913 ms |
95128 KB |
22.txt |
WA |
907 ms |
94360 KB |
23.txt |
WA |
915 ms |
94488 KB |
24.txt |
WA |
927 ms |
92952 KB |
25.txt |
WA |
230 ms |
13108 KB |
26.txt |
WA |
173 ms |
6932 KB |
27.txt |
WA |
941 ms |
94872 KB |
28.txt |
WA |
236 ms |
13620 KB |
29.txt |
WA |
947 ms |
93720 KB |
30.txt |
WA |
248 ms |
12596 KB |
31.txt |
WA |
907 ms |
94872 KB |
32.txt |
WA |
227 ms |
13364 KB |
33.txt |
WA |
171 ms |
6788 KB |
34.txt |
WA |
908 ms |
93720 KB |
35.txt |
WA |
911 ms |
94488 KB |
36.txt |
WA |
1 ms |
256 KB |
37.txt |
AC |
730 ms |
89496 KB |