#include<bits/stdc++.h>
using namespace std;
const int NStu = (int)1e5 + 5, NQue = NStu;
int nStu, nQue, ans[NQue];
vector<int> compMath, compInfo;
struct Stu {
int math, info;
Stu(int _math = 0, int _info = 0) : math(_math), info(_info) {}
bool operator<(const Stu &_) const { return math + info < _.math + _.info; }
} stu[NStu];
struct Que {
int a, b, c, initId;
Que(int _a = 0, int _b = 0, int _c = 0, int _initId = 0) : a(_a), b(_b), c(_c), initId(_initId) {}
bool operator<(const Que &_) const { return c < _.c; }
} que[NQue];
struct Bit2D {
vector<int> infoCnt[NStu];
vector<int> compInfo[NStu];
void updCompInfo(int math, int info) {
int x = (int)(lower_bound(compMath.begin(), compMath.end(), math) - compMath.begin() ) + 1;
for (; x < NStu; x += x & -x) {
compInfo[x].emplace_back(info);
}
}
void prep() {
for (int i = 1; i < NStu; ++i) {
sort(compInfo[i].begin(), compInfo[i].end() );
compInfo[i].erase(unique(compInfo[i].begin(), compInfo[i].end() ), compInfo[i].end() );
infoCnt[i].assign( (int)compInfo[i].size() + 1, 0);
}
}
void upd(int math, int info, int val) {
int x = (int)(lower_bound(compMath.begin(), compMath.end(), math) - compMath.begin() ) + 1;
for (; x < NStu; x += x & -x) {
int y = (int)(lower_bound(compInfo[x].begin() , compInfo[x].end(), info) - compInfo[x].begin() ) + 1;
for (; y < (int)infoCnt[x].size(); y += y & -y) infoCnt[x][y] += val;
}
}
int get(int math, int info) {
int ret = 0,
x = (int)(upper_bound(compMath.begin(), compMath.end(), math) - compMath.begin() );
for (; x > 0; x -= x & -x) {
int y = (int)(upper_bound(compInfo[x].begin() , compInfo[x].end(), info) - compInfo[x].begin() );
for (; y > 0; y -= y & -y) ret += infoCnt[x][y];
}
return ret;
}
} bit2D;
int main() {
// freopen("input", "r", stdin);
scanf(" %d %d", &nStu, &nQue);
for (int i = 1; i <= nStu; ++i) {
scanf(" %d %d", &stu[i].math, &stu[i].info);
stu[i].math = -stu[i].math; compMath.emplace_back(stu[i].math);
stu[i].info = -stu[i].info;
}
sort(stu + 1, stu + nStu + 1);
for (int i = 1; i <= nQue; ++i) {
scanf(" %d %d %d", &que[i].a, &que[i].b, &que[i].c);
que[i].a = -que[i].a;
que[i].b = -que[i].b;
que[i].c = -que[i].c;
que[i].initId = i;
}
sort(que + 1, que + nQue + 1);
sort(compMath.begin(), compMath.end() );
compMath.erase(unique(compMath.begin(), compMath.end() ), compMath.end() );
for (int i = 1; i <= nStu; ++i) {
bit2D.updCompInfo(stu[i].math, stu[i].info);
}
bit2D.prep();
int iStu = 1;
for (int i = 1; i <= nQue; ++i) {
while (iStu <= nStu && stu[iStu].math + stu[iStu].info <= que[i].c) {
bit2D.upd(stu[iStu].math, stu[iStu].info, 1);
++iStu;
}
ans[ que[i].initId ] = bit2D.get(que[i].a, que[i].b);
}
for (int i = 1; i <= nQue; ++i) printf("%d\n", ans[i]);
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %d %d", &nStu, &nQue);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %d %d", &stu[i].math, &stu[i].info);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %d %d %d", &que[i].a, &que[i].b, &que[i].c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
10492 KB |
Output is correct |
2 |
Correct |
15 ms |
10616 KB |
Output is correct |
3 |
Correct |
15 ms |
10488 KB |
Output is correct |
4 |
Correct |
15 ms |
10488 KB |
Output is correct |
5 |
Correct |
15 ms |
10488 KB |
Output is correct |
6 |
Correct |
15 ms |
10488 KB |
Output is correct |
7 |
Correct |
26 ms |
10992 KB |
Output is correct |
8 |
Correct |
26 ms |
11000 KB |
Output is correct |
9 |
Correct |
24 ms |
11000 KB |
Output is correct |
10 |
Correct |
21 ms |
10872 KB |
Output is correct |
11 |
Correct |
23 ms |
11100 KB |
Output is correct |
12 |
Correct |
20 ms |
10812 KB |
Output is correct |
13 |
Correct |
26 ms |
11000 KB |
Output is correct |
14 |
Correct |
25 ms |
11000 KB |
Output is correct |
15 |
Correct |
28 ms |
11000 KB |
Output is correct |
16 |
Correct |
22 ms |
11000 KB |
Output is correct |
17 |
Correct |
23 ms |
10872 KB |
Output is correct |
18 |
Correct |
19 ms |
10872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
514 ms |
20464 KB |
Output is correct |
2 |
Correct |
474 ms |
20576 KB |
Output is correct |
3 |
Correct |
473 ms |
20608 KB |
Output is correct |
4 |
Correct |
221 ms |
17988 KB |
Output is correct |
5 |
Correct |
294 ms |
23380 KB |
Output is correct |
6 |
Correct |
172 ms |
19284 KB |
Output is correct |
7 |
Correct |
460 ms |
20348 KB |
Output is correct |
8 |
Correct |
440 ms |
20420 KB |
Output is correct |
9 |
Correct |
427 ms |
20564 KB |
Output is correct |
10 |
Correct |
244 ms |
23956 KB |
Output is correct |
11 |
Correct |
178 ms |
17648 KB |
Output is correct |
12 |
Correct |
127 ms |
19540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
514 ms |
20464 KB |
Output is correct |
2 |
Correct |
474 ms |
20576 KB |
Output is correct |
3 |
Correct |
473 ms |
20608 KB |
Output is correct |
4 |
Correct |
221 ms |
17988 KB |
Output is correct |
5 |
Correct |
294 ms |
23380 KB |
Output is correct |
6 |
Correct |
172 ms |
19284 KB |
Output is correct |
7 |
Correct |
460 ms |
20348 KB |
Output is correct |
8 |
Correct |
440 ms |
20420 KB |
Output is correct |
9 |
Correct |
427 ms |
20564 KB |
Output is correct |
10 |
Correct |
244 ms |
23956 KB |
Output is correct |
11 |
Correct |
178 ms |
17648 KB |
Output is correct |
12 |
Correct |
127 ms |
19540 KB |
Output is correct |
13 |
Correct |
516 ms |
20520 KB |
Output is correct |
14 |
Correct |
500 ms |
20592 KB |
Output is correct |
15 |
Correct |
490 ms |
20464 KB |
Output is correct |
16 |
Correct |
245 ms |
18032 KB |
Output is correct |
17 |
Correct |
315 ms |
23408 KB |
Output is correct |
18 |
Correct |
176 ms |
19440 KB |
Output is correct |
19 |
Correct |
522 ms |
20560 KB |
Output is correct |
20 |
Correct |
506 ms |
20520 KB |
Output is correct |
21 |
Correct |
491 ms |
20508 KB |
Output is correct |
22 |
Correct |
248 ms |
24060 KB |
Output is correct |
23 |
Correct |
177 ms |
17540 KB |
Output is correct |
24 |
Correct |
125 ms |
19448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
10492 KB |
Output is correct |
2 |
Correct |
15 ms |
10616 KB |
Output is correct |
3 |
Correct |
15 ms |
10488 KB |
Output is correct |
4 |
Correct |
15 ms |
10488 KB |
Output is correct |
5 |
Correct |
15 ms |
10488 KB |
Output is correct |
6 |
Correct |
15 ms |
10488 KB |
Output is correct |
7 |
Correct |
26 ms |
10992 KB |
Output is correct |
8 |
Correct |
26 ms |
11000 KB |
Output is correct |
9 |
Correct |
24 ms |
11000 KB |
Output is correct |
10 |
Correct |
21 ms |
10872 KB |
Output is correct |
11 |
Correct |
23 ms |
11100 KB |
Output is correct |
12 |
Correct |
20 ms |
10812 KB |
Output is correct |
13 |
Correct |
26 ms |
11000 KB |
Output is correct |
14 |
Correct |
25 ms |
11000 KB |
Output is correct |
15 |
Correct |
28 ms |
11000 KB |
Output is correct |
16 |
Correct |
22 ms |
11000 KB |
Output is correct |
17 |
Correct |
23 ms |
10872 KB |
Output is correct |
18 |
Correct |
19 ms |
10872 KB |
Output is correct |
19 |
Correct |
514 ms |
20464 KB |
Output is correct |
20 |
Correct |
474 ms |
20576 KB |
Output is correct |
21 |
Correct |
473 ms |
20608 KB |
Output is correct |
22 |
Correct |
221 ms |
17988 KB |
Output is correct |
23 |
Correct |
294 ms |
23380 KB |
Output is correct |
24 |
Correct |
172 ms |
19284 KB |
Output is correct |
25 |
Correct |
460 ms |
20348 KB |
Output is correct |
26 |
Correct |
440 ms |
20420 KB |
Output is correct |
27 |
Correct |
427 ms |
20564 KB |
Output is correct |
28 |
Correct |
244 ms |
23956 KB |
Output is correct |
29 |
Correct |
178 ms |
17648 KB |
Output is correct |
30 |
Correct |
127 ms |
19540 KB |
Output is correct |
31 |
Correct |
516 ms |
20520 KB |
Output is correct |
32 |
Correct |
500 ms |
20592 KB |
Output is correct |
33 |
Correct |
490 ms |
20464 KB |
Output is correct |
34 |
Correct |
245 ms |
18032 KB |
Output is correct |
35 |
Correct |
315 ms |
23408 KB |
Output is correct |
36 |
Correct |
176 ms |
19440 KB |
Output is correct |
37 |
Correct |
522 ms |
20560 KB |
Output is correct |
38 |
Correct |
506 ms |
20520 KB |
Output is correct |
39 |
Correct |
491 ms |
20508 KB |
Output is correct |
40 |
Correct |
248 ms |
24060 KB |
Output is correct |
41 |
Correct |
177 ms |
17540 KB |
Output is correct |
42 |
Correct |
125 ms |
19448 KB |
Output is correct |
43 |
Correct |
536 ms |
20860 KB |
Output is correct |
44 |
Correct |
538 ms |
20732 KB |
Output is correct |
45 |
Correct |
536 ms |
20544 KB |
Output is correct |
46 |
Correct |
264 ms |
18056 KB |
Output is correct |
47 |
Correct |
323 ms |
25460 KB |
Output is correct |
48 |
Correct |
180 ms |
18800 KB |
Output is correct |
49 |
Correct |
516 ms |
20588 KB |
Output is correct |
50 |
Correct |
510 ms |
20720 KB |
Output is correct |
51 |
Correct |
473 ms |
20560 KB |
Output is correct |
52 |
Correct |
297 ms |
26180 KB |
Output is correct |
53 |
Correct |
197 ms |
17752 KB |
Output is correct |