#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
struct query_t{
int a,b,c;
int id;
bool operator < (const query_t &other)const{
if(c != other.c)return c > other.c;
return id < other.id;
}
};
class AIB2d{
public:
int n;
vector<vector<int> > stuff;
vector<vector<int> > aib;
AIB2d(int n){
this->n = n;
stuff = vector<vector<int>>(n + 1,vector<int>(1,-1));
aib = vector<vector<int>>(n + 1,vector<int>(1,-1));
}
void preupdate(int x,int y){
for(int xx = x;xx > 0;xx -= (-xx & xx)){
stuff[xx].push_back(y);
}
}
void init(){
for(int i = 1;i <= n;i++){
sort(stuff[i].begin(),stuff[i].end());
stuff[i].resize(unique(stuff[i].begin(),stuff[i].end()) - stuff[i].begin());
aib[i] = vector<int>(stuff[i].size(),0);
}
}
void update(int x,int y,int val){
for(int xx = x;xx > 0;xx -= (-xx & xx)){
for(int yy = lower_bound(stuff[xx].begin(),stuff[xx].end(),y) - stuff[xx].begin();yy > 0;yy -= (-yy & yy)){
aib[xx][yy] += val;
}
}
}
int query(int x,int y){
int ans = 0;
for(int xx = x;xx <= n;xx += (-xx & xx)){
for(int yy = lower_bound(stuff[xx].begin(),stuff[xx].end(),y) - stuff[xx].begin();yy < (int)stuff[xx].size();yy += (-yy & yy)){
ans += aib[xx][yy];
}
}
return ans;
}
};
int n,q;
int ans[100005];
vector<query_t> events;
int main(){
scanf("%d %d",&n,&q);
map<int,int> to_norm;
for(int i = 1;i <= n;i++){
int x,y;
scanf("%d %d",&x,&y);
events.push_back({x,y,x + y,i - n});
to_norm[x] = 1;
}
for(int i = 1;i <= q;i++){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
events.push_back({a,b,c,i});
to_norm[a] = 1;
}
sort(events.begin(),events.end());
int last = 0;
for(auto &it:to_norm){
it.second = ++last;
}
AIB2d aib(last);
for(auto it:events){
if(it.id <= 0){
aib.preupdate(to_norm[it.a],it.b);
}
}
aib.init();
for(auto it:events){
if(it.id <= 0){
aib.update(to_norm[it.a],it.b,1);
}
else{
ans[it.id] = aib.query(to_norm[it.a],it.b);
}
}
for(int i = 1;i <= q;i++){
printf("%d\n",ans[i]);
}
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n,&q);
~~~~~^~~~~~~~~~~~~~~
examination.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&x,&y);
~~~~~^~~~~~~~~~~~~~~
examination.cpp:83:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&a,&b,&c);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
14 ms |
1528 KB |
Output is correct |
8 |
Correct |
14 ms |
1528 KB |
Output is correct |
9 |
Correct |
14 ms |
1528 KB |
Output is correct |
10 |
Correct |
11 ms |
1528 KB |
Output is correct |
11 |
Correct |
6 ms |
632 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
14 ms |
1656 KB |
Output is correct |
14 |
Correct |
13 ms |
1656 KB |
Output is correct |
15 |
Correct |
13 ms |
1660 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
11 ms |
1528 KB |
Output is correct |
18 |
Correct |
4 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
651 ms |
25076 KB |
Output is correct |
2 |
Correct |
681 ms |
27564 KB |
Output is correct |
3 |
Correct |
674 ms |
27776 KB |
Output is correct |
4 |
Correct |
368 ms |
24540 KB |
Output is correct |
5 |
Correct |
153 ms |
7932 KB |
Output is correct |
6 |
Correct |
99 ms |
6492 KB |
Output is correct |
7 |
Correct |
584 ms |
23872 KB |
Output is correct |
8 |
Correct |
633 ms |
27616 KB |
Output is correct |
9 |
Correct |
541 ms |
23904 KB |
Output is correct |
10 |
Correct |
103 ms |
6876 KB |
Output is correct |
11 |
Correct |
306 ms |
23772 KB |
Output is correct |
12 |
Correct |
70 ms |
5984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
651 ms |
25076 KB |
Output is correct |
2 |
Correct |
681 ms |
27564 KB |
Output is correct |
3 |
Correct |
674 ms |
27776 KB |
Output is correct |
4 |
Correct |
368 ms |
24540 KB |
Output is correct |
5 |
Correct |
153 ms |
7932 KB |
Output is correct |
6 |
Correct |
99 ms |
6492 KB |
Output is correct |
7 |
Correct |
584 ms |
23872 KB |
Output is correct |
8 |
Correct |
633 ms |
27616 KB |
Output is correct |
9 |
Correct |
541 ms |
23904 KB |
Output is correct |
10 |
Correct |
103 ms |
6876 KB |
Output is correct |
11 |
Correct |
306 ms |
23772 KB |
Output is correct |
12 |
Correct |
70 ms |
5984 KB |
Output is correct |
13 |
Correct |
703 ms |
27996 KB |
Output is correct |
14 |
Correct |
779 ms |
27964 KB |
Output is correct |
15 |
Correct |
715 ms |
27588 KB |
Output is correct |
16 |
Correct |
389 ms |
24924 KB |
Output is correct |
17 |
Correct |
171 ms |
8256 KB |
Output is correct |
18 |
Correct |
110 ms |
6616 KB |
Output is correct |
19 |
Correct |
711 ms |
27984 KB |
Output is correct |
20 |
Correct |
765 ms |
28012 KB |
Output is correct |
21 |
Correct |
669 ms |
26556 KB |
Output is correct |
22 |
Correct |
103 ms |
6876 KB |
Output is correct |
23 |
Correct |
349 ms |
23700 KB |
Output is correct |
24 |
Correct |
72 ms |
5952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
14 ms |
1528 KB |
Output is correct |
8 |
Correct |
14 ms |
1528 KB |
Output is correct |
9 |
Correct |
14 ms |
1528 KB |
Output is correct |
10 |
Correct |
11 ms |
1528 KB |
Output is correct |
11 |
Correct |
6 ms |
632 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
14 ms |
1656 KB |
Output is correct |
14 |
Correct |
13 ms |
1656 KB |
Output is correct |
15 |
Correct |
13 ms |
1660 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
11 ms |
1528 KB |
Output is correct |
18 |
Correct |
4 ms |
524 KB |
Output is correct |
19 |
Correct |
651 ms |
25076 KB |
Output is correct |
20 |
Correct |
681 ms |
27564 KB |
Output is correct |
21 |
Correct |
674 ms |
27776 KB |
Output is correct |
22 |
Correct |
368 ms |
24540 KB |
Output is correct |
23 |
Correct |
153 ms |
7932 KB |
Output is correct |
24 |
Correct |
99 ms |
6492 KB |
Output is correct |
25 |
Correct |
584 ms |
23872 KB |
Output is correct |
26 |
Correct |
633 ms |
27616 KB |
Output is correct |
27 |
Correct |
541 ms |
23904 KB |
Output is correct |
28 |
Correct |
103 ms |
6876 KB |
Output is correct |
29 |
Correct |
306 ms |
23772 KB |
Output is correct |
30 |
Correct |
70 ms |
5984 KB |
Output is correct |
31 |
Correct |
703 ms |
27996 KB |
Output is correct |
32 |
Correct |
779 ms |
27964 KB |
Output is correct |
33 |
Correct |
715 ms |
27588 KB |
Output is correct |
34 |
Correct |
389 ms |
24924 KB |
Output is correct |
35 |
Correct |
171 ms |
8256 KB |
Output is correct |
36 |
Correct |
110 ms |
6616 KB |
Output is correct |
37 |
Correct |
711 ms |
27984 KB |
Output is correct |
38 |
Correct |
765 ms |
28012 KB |
Output is correct |
39 |
Correct |
669 ms |
26556 KB |
Output is correct |
40 |
Correct |
103 ms |
6876 KB |
Output is correct |
41 |
Correct |
349 ms |
23700 KB |
Output is correct |
42 |
Correct |
72 ms |
5952 KB |
Output is correct |
43 |
Correct |
943 ms |
47688 KB |
Output is correct |
44 |
Correct |
947 ms |
47612 KB |
Output is correct |
45 |
Correct |
893 ms |
47560 KB |
Output is correct |
46 |
Correct |
544 ms |
43600 KB |
Output is correct |
47 |
Correct |
185 ms |
9440 KB |
Output is correct |
48 |
Correct |
109 ms |
6320 KB |
Output is correct |
49 |
Correct |
896 ms |
48860 KB |
Output is correct |
50 |
Correct |
928 ms |
47640 KB |
Output is correct |
51 |
Correct |
850 ms |
48812 KB |
Output is correct |
52 |
Correct |
136 ms |
8540 KB |
Output is correct |
53 |
Correct |
484 ms |
42308 KB |
Output is correct |