# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
803778 |
2023-08-03T05:59:31 Z |
반딧불(#10100) |
Vera and Modern Art (CCO17_art) |
C++17 |
|
1489 ms |
50988 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Query{
bool type; int y, xl, xr; ll v; /// ���簢�� 0, ���� 1
Query(){}
Query(bool type, int y, int xl, int xr, ll v): type(type), y(y), xl(xl), xr(xr), v(v){}
bool operator<(const Query &r)const{
if(y != r.y) return y < r.y;
return type < r.type;
}
};
struct Fenwick{
int n;
ll tree[1000002];
void init(int _n){
n = _n;
for(int i=1; i<=n; i++) tree[i] = 0;
}
void add(int x, ll y){
while(x<=n){
tree[x] += y;
x += x&-x;
}
}
ll sum(int x){
ll ret = 0;
while(x){
ret += tree[x];
x -= x&-x;
}
return ret;
}
ll sum(int l, int r){
if(l>r) return 0;
return sum(r) - sum(l-1);
}
} fenwick;
int n, q;
ll px[200002], py[200002], pa[200002], pb[200002], pv[200002];
ll qx[200002], qy[200002];
int pxl[200002], pxr[200002], pyl[200002], pyr[200002];
int ax[200002], ay[200002];
int inCnt;
void makeTree(ll b, ll digit, bool where, vector<int> &ia, vector<int> &iq){
ll *va = (where ? py : px), *vb = (where ? qy : qx);
int *pl = (where ? pyl : pxl), *pr = (where ? pyr : pxr), *qv = (where ? ay : ax);
inCnt++;
// printf("B %lld, digit %d, where %c\n", b, digit, where ? 'Y' : 'X');
// for(int x: ia) printf("%lld ", va[x]); puts("");
// for(int x: iq) printf("%lld ", vb[x]); puts("");
vector<int> via, vib, vqa, vqb;
for(int x: ia){
if(b == va[x]) pl[x] = inCnt;
else if((va[x]>>digit)&1) vib.push_back(x);
else via.push_back(x);
}
for(int x: iq){
if(b == vb[x]) qv[x] = inCnt;
else if((vb[x]>>digit)&1) vqb.push_back(x);
else vqa.push_back(x);
}
if(!vqa.empty()) makeTree(b+(1LL<<digit), digit+1, where, via, vqa);
if(!vqb.empty()) makeTree(b+(2LL<<digit), digit+1, where, vib, vqb);
for(int x: ia) if(b == va[x]) pr[x] = inCnt;
}
ll ans[200002];
int main(){
scanf("%d %d", &n, &q);
for(int i=1; i<=n; i++){
scanf("%lld %lld %lld", &px[i], &py[i], &pv[i]);
pa[i] = 1, pb[i] = 1;
while(pa[i] * 2 <= px[i]) pa[i]*=2;
while(pb[i] * 2 <= py[i]) pb[i]*=2;
}
for(int i=1; i<=q; i++) scanf("%lld %lld", &qx[i], &qy[i]);
vector<int> bvec, qvec;
for(int i=1; i<=n; i++) bvec.push_back(i);
for(int i=1; i<=q; i++) qvec.push_back(i);
inCnt = 0;
makeTree(1, 0, 0, bvec, qvec);
inCnt = 0;
makeTree(1, 0, 1, bvec, qvec);
vector<int> vx, vy;
for(int i=1; i<=n; i++){
if(!pxl[i] || !pxr[i] || !pyl[i] || !pyr[i]) continue;
vx.push_back(pxl[i]), vx.push_back(pxr[i]);
vy.push_back(pyl[i]), vx.push_back(pyr[i]);
}
for(int i=1; i<=q; i++){
if(!ax[i] || !ay[i]) continue;
vx.push_back(ax[i]), vy.push_back(ay[i]);
}
sort(vx.begin(), vx.end());
vx.erase(unique(vx.begin(), vx.end()), vx.end());
sort(vy.begin(), vy.end());
vy.erase(unique(vy.begin(), vy.end()), vy.end());
int sx = (int)vx.size();
for(int i=1; i<=n; i++){
if(!pxl[i] || !pxr[i] || !pyl[i] || !pyr[i]) continue;
pxl[i] = lower_bound(vx.begin(), vx.end(), pxl[i]) - vx.begin() + 1;
pxr[i] = lower_bound(vx.begin(), vx.end(), pxr[i]) - vx.begin() + 1;
pyl[i] = lower_bound(vy.begin(), vy.end(), pyl[i]) - vy.begin() + 1;
pyr[i] = lower_bound(vy.begin(), vy.end(), pyr[i]) - vy.begin() + 1;
}
for(int i=1; i<=q; i++){
if(!ax[i] || !ay[i]) continue;
ax[i] = lower_bound(vx.begin(), vx.end(), ax[i]) - vx.begin() + 1;
ay[i] = lower_bound(vy.begin(), vy.end(), ay[i]) - vy.begin() + 1;
}
vector<Query> vec;
for(int i=1; i<=n; i++){
if(!pxl[i] || !pxr[i] || !pyl[i] || !pyr[i]) continue;
vec.push_back(Query(0, pyl[i], pxl[i], pxr[i], pv[i]));
vec.push_back(Query(0, pyr[i]+1, pxl[i], pxr[i], -pv[i]));
}
for(int i=1; i<=q; i++){
if(!ax[i] || !ay[i]) continue;
vec.push_back(Query(1, ay[i], ax[i], ax[i], i));
}
sort(vec.begin(), vec.end());
fenwick.init(sx);
for(Query &p: vec){
if(p.type == 0) fenwick.add(p.xl, p.v), fenwick.add(p.xr+1, -p.v);
else ans[p.v] = fenwick.sum(1, p.xl);
}
for(int i=1; i<=q; i++){
printf("%lld\n", ans[i]);
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | scanf("%d %d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:91:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | scanf("%lld %lld %lld", &px[i], &py[i], &pv[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:96:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | for(int i=1; i<=q; i++) scanf("%lld %lld", &qx[i], &qy[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
14 ms |
940 KB |
Output is correct |
3 |
Correct |
14 ms |
944 KB |
Output is correct |
4 |
Correct |
15 ms |
936 KB |
Output is correct |
5 |
Correct |
20 ms |
940 KB |
Output is correct |
6 |
Correct |
9 ms |
724 KB |
Output is correct |
7 |
Correct |
7 ms |
780 KB |
Output is correct |
8 |
Correct |
7 ms |
788 KB |
Output is correct |
9 |
Correct |
7 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
724 KB |
Output is correct |
11 |
Correct |
7 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1154 ms |
39628 KB |
Output is correct |
2 |
Correct |
1195 ms |
39664 KB |
Output is correct |
3 |
Correct |
1271 ms |
50932 KB |
Output is correct |
4 |
Correct |
1282 ms |
50988 KB |
Output is correct |
5 |
Correct |
617 ms |
35744 KB |
Output is correct |
6 |
Correct |
608 ms |
36964 KB |
Output is correct |
7 |
Correct |
608 ms |
36964 KB |
Output is correct |
8 |
Correct |
634 ms |
35820 KB |
Output is correct |
9 |
Correct |
607 ms |
36028 KB |
Output is correct |
10 |
Correct |
615 ms |
37056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
386 ms |
20552 KB |
Output is correct |
3 |
Correct |
378 ms |
20492 KB |
Output is correct |
4 |
Correct |
404 ms |
25664 KB |
Output is correct |
5 |
Correct |
419 ms |
25720 KB |
Output is correct |
6 |
Correct |
220 ms |
18544 KB |
Output is correct |
7 |
Correct |
220 ms |
18480 KB |
Output is correct |
8 |
Correct |
237 ms |
18508 KB |
Output is correct |
9 |
Correct |
213 ms |
18500 KB |
Output is correct |
10 |
Correct |
213 ms |
18588 KB |
Output is correct |
11 |
Correct |
216 ms |
18584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
14 ms |
940 KB |
Output is correct |
3 |
Correct |
14 ms |
944 KB |
Output is correct |
4 |
Correct |
15 ms |
936 KB |
Output is correct |
5 |
Correct |
20 ms |
940 KB |
Output is correct |
6 |
Correct |
9 ms |
724 KB |
Output is correct |
7 |
Correct |
7 ms |
780 KB |
Output is correct |
8 |
Correct |
7 ms |
788 KB |
Output is correct |
9 |
Correct |
7 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
724 KB |
Output is correct |
11 |
Correct |
7 ms |
724 KB |
Output is correct |
12 |
Correct |
1154 ms |
39628 KB |
Output is correct |
13 |
Correct |
1195 ms |
39664 KB |
Output is correct |
14 |
Correct |
1271 ms |
50932 KB |
Output is correct |
15 |
Correct |
1282 ms |
50988 KB |
Output is correct |
16 |
Correct |
617 ms |
35744 KB |
Output is correct |
17 |
Correct |
608 ms |
36964 KB |
Output is correct |
18 |
Correct |
608 ms |
36964 KB |
Output is correct |
19 |
Correct |
634 ms |
35820 KB |
Output is correct |
20 |
Correct |
607 ms |
36028 KB |
Output is correct |
21 |
Correct |
615 ms |
37056 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
386 ms |
20552 KB |
Output is correct |
24 |
Correct |
378 ms |
20492 KB |
Output is correct |
25 |
Correct |
404 ms |
25664 KB |
Output is correct |
26 |
Correct |
419 ms |
25720 KB |
Output is correct |
27 |
Correct |
220 ms |
18544 KB |
Output is correct |
28 |
Correct |
220 ms |
18480 KB |
Output is correct |
29 |
Correct |
237 ms |
18508 KB |
Output is correct |
30 |
Correct |
213 ms |
18500 KB |
Output is correct |
31 |
Correct |
213 ms |
18588 KB |
Output is correct |
32 |
Correct |
216 ms |
18584 KB |
Output is correct |
33 |
Correct |
1384 ms |
40684 KB |
Output is correct |
34 |
Correct |
1367 ms |
40572 KB |
Output is correct |
35 |
Correct |
1473 ms |
50912 KB |
Output is correct |
36 |
Correct |
1489 ms |
50876 KB |
Output is correct |
37 |
Correct |
666 ms |
32088 KB |
Output is correct |
38 |
Correct |
656 ms |
32216 KB |
Output is correct |
39 |
Correct |
656 ms |
32176 KB |
Output is correct |
40 |
Correct |
658 ms |
32164 KB |
Output is correct |
41 |
Correct |
684 ms |
32084 KB |
Output is correct |
42 |
Correct |
653 ms |
32212 KB |
Output is correct |