답안 #756684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
756684 2023-06-12T05:00:02 Z boyliguanhan 가로등 (APIO19_street_lamps) C++17
100 / 100
2744 ms 173256 KB
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define doi(x) cout << #x << " = " << x << '\n'
using namespace std;
#define N 15000100
#define mid ((rl+rr)>>1)
int root[300100], n, q, on[300100], sum[N], ch[N][2], cnt;
void upd1(int &rt,int rl,int rr,int x,int w){
	if (!rt) rt=++cnt;sum[rt]+=w;
	if (rl==rr) return;
	(mid>=x?upd1(ch[rt][0],rl,mid,x,w):upd1(ch[rt][1],mid+1,rr,x,w));
}
int query1(int rt,int rl,int rr,int l,int r){
	if (!rt||rl>r||rr<l) return 0;
	if (rl>=l&&rr<=r) return sum[rt];
	return query1(ch[rt][0],rl,mid,l,r)+query1(ch[rt][1],mid+1,rr,l,r);
}
inline void upd2(int x,int r,int w){
	while(x<=n+1)
        upd1(root[x],1,n+1,r,w),x+=x&-x;
}
inline int query2(int x,int y){
	int ans=0;
	while(x)
        ans+=query1(root[x],1,n+1,1,y),x-=x&-x;
	return ans;
}
inline void upd3(int x1, int y1, int x2, int y2, int W) {
    upd2(x1, y1, W);
    query2(5,6);
    upd2(x1, y2 + 1, -W);
    upd2(x2 + 1, y1, -W);
    upd2(x2 + 1, y2 + 1, W);
}
struct seg{
    int l, r;
};
inline bool operator < (seg a,seg b){
	return a.r<b.r;
} 
set<seg> st;
int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> q;
    n++;
    string str;
    cin >> str;
    for (int i=1;i<=n;i++){
		st.insert((seg){i,i});
	}
	for (int i=1;i<n;i++){
		on[i]=(str[i-1]-48);
		if (on[i]){
            auto it = --st.lower_bound((seg){0,i+1});
			int l = it->l;
			st.erase(it);st.erase((seg){i+1,i+1});
			st.insert((seg){l,i+1});
		}
	}
    for(auto i: st)
        if(on[i.l])
            upd3(i.l,i.l,i.r,i.r,q);
    for (int t=1;t<=q;t++){
		cin >> str;
		if (str=="query"){
			int x, y;
            cin >> x >> y;
			int ans=query2(x,y);
			x=(*(st.lower_bound((seg){0,x}))).l;
			y=(*(st.lower_bound((seg){0,y}))).l;
			cout << (ans-(q-t)*(x==y)) << '\n';
		} else {
			int x;
            cin >> x;
			auto it=st.lower_bound((seg){0,x});
			int lb1=it->l,rb1=x;
            if(!on[x]) it++;
			int lb2=x+1,rb2=it->r;
			upd3(lb1,lb2,rb1,rb2,(on[x]?t-q:q-t));
            if(on[x]) {
				st.erase((seg){lb1,rb2});
				st.insert((seg){lb1,rb1});
                st.insert((seg){lb2,rb2}); 
            } else {
				st.erase((seg){lb1,rb1});
                st.erase((seg){lb2,rb2});
				st.insert((seg){lb1,rb2}); 
            }
			on[x]^=1;
		}
	}
}

Compilation message

street_lamps.cpp: In function 'void upd1(int&, int, int, int, int)':
street_lamps.cpp:9:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    9 |  if (!rt) rt=++cnt;sum[rt]+=w;
      |  ^~
street_lamps.cpp:9:20: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    9 |  if (!rt) rt=++cnt;sum[rt]+=w;
      |                    ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 261 ms 1488 KB Output is correct
2 Correct 360 ms 1612 KB Output is correct
3 Correct 672 ms 4224 KB Output is correct
4 Correct 2258 ms 136668 KB Output is correct
5 Correct 2230 ms 119144 KB Output is correct
6 Correct 2392 ms 140920 KB Output is correct
7 Correct 393 ms 16832 KB Output is correct
8 Correct 235 ms 18296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 724 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2346 ms 173256 KB Output is correct
6 Correct 2151 ms 152044 KB Output is correct
7 Correct 1727 ms 118644 KB Output is correct
8 Correct 241 ms 18320 KB Output is correct
9 Correct 82 ms 1460 KB Output is correct
10 Correct 90 ms 1516 KB Output is correct
11 Correct 82 ms 1504 KB Output is correct
12 Correct 537 ms 16800 KB Output is correct
13 Correct 238 ms 18296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 464 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 1155 ms 104820 KB Output is correct
6 Correct 1569 ms 126372 KB Output is correct
7 Correct 2090 ms 140660 KB Output is correct
8 Correct 2744 ms 152660 KB Output is correct
9 Correct 379 ms 696 KB Output is correct
10 Correct 330 ms 460 KB Output is correct
11 Correct 389 ms 660 KB Output is correct
12 Correct 338 ms 384 KB Output is correct
13 Correct 380 ms 640 KB Output is correct
14 Correct 331 ms 468 KB Output is correct
15 Correct 468 ms 16488 KB Output is correct
16 Correct 239 ms 17876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 261 ms 1488 KB Output is correct
9 Correct 360 ms 1612 KB Output is correct
10 Correct 672 ms 4224 KB Output is correct
11 Correct 2258 ms 136668 KB Output is correct
12 Correct 2230 ms 119144 KB Output is correct
13 Correct 2392 ms 140920 KB Output is correct
14 Correct 393 ms 16832 KB Output is correct
15 Correct 235 ms 18296 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2346 ms 173256 KB Output is correct
21 Correct 2151 ms 152044 KB Output is correct
22 Correct 1727 ms 118644 KB Output is correct
23 Correct 241 ms 18320 KB Output is correct
24 Correct 82 ms 1460 KB Output is correct
25 Correct 90 ms 1516 KB Output is correct
26 Correct 82 ms 1504 KB Output is correct
27 Correct 537 ms 16800 KB Output is correct
28 Correct 238 ms 18296 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 1155 ms 104820 KB Output is correct
34 Correct 1569 ms 126372 KB Output is correct
35 Correct 2090 ms 140660 KB Output is correct
36 Correct 2744 ms 152660 KB Output is correct
37 Correct 379 ms 696 KB Output is correct
38 Correct 330 ms 460 KB Output is correct
39 Correct 389 ms 660 KB Output is correct
40 Correct 338 ms 384 KB Output is correct
41 Correct 380 ms 640 KB Output is correct
42 Correct 331 ms 468 KB Output is correct
43 Correct 468 ms 16488 KB Output is correct
44 Correct 239 ms 17876 KB Output is correct
45 Correct 92 ms 844 KB Output is correct
46 Correct 156 ms 556 KB Output is correct
47 Correct 936 ms 47728 KB Output is correct
48 Correct 1954 ms 136416 KB Output is correct
49 Correct 92 ms 884 KB Output is correct
50 Correct 91 ms 956 KB Output is correct
51 Correct 95 ms 1020 KB Output is correct
52 Correct 100 ms 1036 KB Output is correct
53 Correct 101 ms 1028 KB Output is correct
54 Correct 99 ms 1100 KB Output is correct