# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
333237 |
2020-12-05T04:08:23 Z |
CodeTiger927 |
Pairs (IOI07_pairs) |
C++14 |
|
4000 ms |
524292 KB |
using namespace std;
#include <iostream>
int B,D,N,M;
struct node1d {
int v;
node1d *c[2];
node1d() {
v = 0;
c[0] = nullptr;
c[1] = nullptr;
}
void upd(int l,int r,int x,int v) {
this -> v += v;
if(l != r) {
int m = (l + r) >> 1;
if(x <= m) {
if(!c[0]) c[0] = new node1d();
c[0] -> upd(l,m,x,v);
}else{
if(!c[1]) c[1] = new node1d();
c[1] -> upd(m + 1,r,x,v);
}
}
}
int qry(int l,int r,int x,int y) {
if(x <= l && r <= y) return v;
if(y < l || x > r) return 0;
int res = 0;
int m = (l + r) >> 1;
if(c[0]) res += c[0] -> qry(l,m,x,y);
if(c[1]) res += c[1] -> qry(m + 1,r,x,y);
return res;
}
};
struct node2d {
int l,r;
node1d* v;
node2d *c[2];
node2d(int l,int r) : l{l}, r{r} {
if(B == 3) {
v = new node1d();
}else{
v = new node1d();
}
c[0] = nullptr;
c[1] = nullptr;
}
void upd(int x,int y,int v) {
this -> v -> upd(0,2 * M,y,v);
if(l != r) {
int m = (l + r) >> 1;
if(x <= m) {
if(!c[0]) c[0] = new node2d(l,m);
c[0] -> upd(x,y,v);
}else{
if(!c[1]) c[1] = new node2d(m + 1,r);
c[1] -> upd(x,y,v);
}
}
}
int qry(int x1,int x2,int y1,int y2) {
if(x1 <= l && r <= x2) return v -> qry(0,2 * M,y1,y2);
if(x2 < l || x1 > r) return 0;
int res = 0;
if(c[0]) res += c[0] -> qry(x1,x2,y1,y2);
if(c[1]) res += c[1] -> qry(x1,x2,y1,y2);
return res;
}
};
int main() {
scanf("%d %d %d %d",&B,&N,&D,&M);
long long ans = 0;
if(B == 1) {
node1d* st = new node1d();
for(int i = 0;i < N;++i) {
int a;
scanf("%d",&a);
ans += st -> qry(0,M,max(0,a - D),a + D);
st -> upd(0,M,a,1);
}
}else if(B == 2) {
node2d* st = new node2d(0,2 * M);
for(int i = 0;i < N;++i) {
int c,d;
scanf("%d %d",&c,&d);
int a = (c + d);
int b = (c - d) + M;
ans += st -> qry(max(0,a - D),a + D,max(0,b - D),b + D);
st -> upd(a,b,1);
}
}else{
node2d* st[80];
for(int i = 0;i <= M;++i) {
st[i] = new node2d(0,160);
}
for(int i = 0;i < N;++i) {
int d,e,f;
scanf("%d %d %d",&d,&e,&f);
int a = (d + e);
int b = (d - e) + M;
int c = f;
// cout << a << " " << b << " " << c << endl;
for(int j = 0;j <= M;++j) {
int curD = D - abs(c - j);
if(curD < 0) continue;
ans += st[j] -> qry(max(0,a - curD),a + curD,max(0,b - curD),b + curD);
}
st[c] -> upd(a,b,1);
}
}
printf("%lld\n",ans);
return 0;
}
Compilation message
pairs.cpp: In function 'int main()':
pairs.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
76 | scanf("%d %d %d %d",&B,&N,&D,&M);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:82:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
82 | scanf("%d",&a);
| ~~~~~^~~~~~~~~
pairs.cpp:90:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
90 | scanf("%d %d",&c,&d);
| ~~~~~^~~~~~~~~~~~~~~
pairs.cpp:103:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
103 | scanf("%d %d %d",&d,&e,&f);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
364 KB |
Output is correct |
2 |
Correct |
23 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
33516 KB |
Output is correct |
2 |
Correct |
106 ms |
33516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
33476 KB |
Output is correct |
2 |
Correct |
103 ms |
6636 KB |
Output is correct |
3 |
Correct |
57 ms |
1516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
9196 KB |
Output is correct |
2 |
Correct |
16 ms |
9196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
2668 KB |
Output is correct |
2 |
Correct |
86 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1085 ms |
67056 KB |
Output is correct |
2 |
Correct |
869 ms |
67308 KB |
Output is correct |
3 |
Correct |
650 ms |
34924 KB |
Output is correct |
4 |
Correct |
676 ms |
53612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2658 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2304 KB |
Output is correct |
2 |
Correct |
5 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
888 KB |
Output is correct |
2 |
Correct |
308 ms |
1132 KB |
Output is correct |
3 |
Correct |
74 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3351 ms |
33516 KB |
Output is correct |
2 |
Execution timed out |
4051 ms |
22612 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4078 ms |
32164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |