답안 #603887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603887 2022-07-24T13:01:45 Z OttoTheDino 가로등 (APIO19_street_lamps) C++17
100 / 100
2770 ms 114716 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,e)				  for (int i = s; i <= e; ++i)
#define pb						  push_back
#define fi						  first
#define se						  second
#define len(a)					  (int)a.size()
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int mx = 3e5;
int ans[mx+1], ft[mx+1];
vector<vi> g;

void upd (int x, int id) {
	for (;id<=mx;id+=id&(-id)) ft[id] += x;
}
int qry (int id) {
	int res = 0;
	for (;id;id-=id&(-id)) res += ft[id];
	return res;
}

void cdq (int l, int r) {
	if (l==r) return;
	int mid = (l+r)/2;
	cdq (l, mid);
	cdq (mid+1, r);
	vii undo;
	vector<vi> nxt;
	int a = l, b = mid+1, k = l;
	while (k<=r) {
		if (a>mid || (b<=r && g[b]<g[a])) nxt.pb(g[b++]);
		else nxt.pb(g[a++]);
		++k;
	}
	rep (i,l,r) g[i] = nxt[i-l];
	rep (i,l,r) {
		int y = g[i][1], id = g[i][2], delt = g[i][3], t = g[i][4];
		if (t>mid) ans[id] += qry(y);
		else {
			upd(delt,y);
			undo.pb({delt,y});
		}
	}
	for (ii el : undo) upd(-el.fi, el.se);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, q; cin >> n >> q;
	bool b[n+1]; 
	string s; cin >> s;
	set<int> st;
	st.insert(0);
	st.insert(n+1);
	rep (i,1,n) {
		b[i] = s[i-1]-'0';
		if (!b[i]) st.insert(i);
	}
	vi get;
	rep (i,1,q) {
		string tp; cin >> tp;
		int t = len(g);
		if (tp[0]=='t') {
			int u; cin >> u;
			int prv = *--st.lower_bound(u)+1, nxt = *st.upper_bound(u)-1, c = 2*b[u]-1;
			g.pb({prv,mx+1-nxt,0,c*i,t++}); 
			if (u+1<=mx) g.pb({u+1,mx+1-nxt,0,-c*i,t++});
			if (u-1>0) g.pb({prv,mx+1-(u-1),0,-c*i,t++});
			if (b[u]) st.insert(u);
			else st.erase(u);
			b[u] ^= 1;
		}
		else {
			int x, y; cin >> x >> y;
			--y;
			get.pb(i);
			if (*st.lower_bound(x)>y) ans[i] += i;
			g.pb({x,mx+1-y,i,0,t++});
		}
	}
	cdq(0,len(g)-1);
	for (int el : get) cout << ans[el] << "\n";

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 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 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1194 ms 77576 KB Output is correct
2 Correct 1227 ms 77812 KB Output is correct
3 Correct 1305 ms 78016 KB Output is correct
4 Correct 1519 ms 86660 KB Output is correct
5 Correct 1507 ms 76936 KB Output is correct
6 Correct 1661 ms 90508 KB Output is correct
7 Correct 941 ms 56380 KB Output is correct
8 Correct 750 ms 42340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2770 ms 113580 KB Output is correct
6 Correct 2259 ms 93236 KB Output is correct
7 Correct 1470 ms 76744 KB Output is correct
8 Correct 745 ms 42448 KB Output is correct
9 Correct 483 ms 30740 KB Output is correct
10 Correct 501 ms 37632 KB Output is correct
11 Correct 486 ms 37408 KB Output is correct
12 Correct 966 ms 56344 KB Output is correct
13 Correct 764 ms 42284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 4 ms 672 KB Output is correct
4 Correct 5 ms 724 KB Output is correct
5 Correct 996 ms 49676 KB Output is correct
6 Correct 1467 ms 67388 KB Output is correct
7 Correct 1908 ms 90540 KB Output is correct
8 Correct 2515 ms 114716 KB Output is correct
9 Correct 1529 ms 88988 KB Output is correct
10 Correct 1693 ms 105228 KB Output is correct
11 Correct 1482 ms 88924 KB Output is correct
12 Correct 1674 ms 105208 KB Output is correct
13 Correct 1447 ms 89020 KB Output is correct
14 Correct 1676 ms 105252 KB Output is correct
15 Correct 922 ms 56348 KB Output is correct
16 Correct 710 ms 42396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 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 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1194 ms 77576 KB Output is correct
9 Correct 1227 ms 77812 KB Output is correct
10 Correct 1305 ms 78016 KB Output is correct
11 Correct 1519 ms 86660 KB Output is correct
12 Correct 1507 ms 76936 KB Output is correct
13 Correct 1661 ms 90508 KB Output is correct
14 Correct 941 ms 56380 KB Output is correct
15 Correct 750 ms 42340 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2770 ms 113580 KB Output is correct
21 Correct 2259 ms 93236 KB Output is correct
22 Correct 1470 ms 76744 KB Output is correct
23 Correct 745 ms 42448 KB Output is correct
24 Correct 483 ms 30740 KB Output is correct
25 Correct 501 ms 37632 KB Output is correct
26 Correct 486 ms 37408 KB Output is correct
27 Correct 966 ms 56344 KB Output is correct
28 Correct 764 ms 42284 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 4 ms 672 KB Output is correct
32 Correct 5 ms 724 KB Output is correct
33 Correct 996 ms 49676 KB Output is correct
34 Correct 1467 ms 67388 KB Output is correct
35 Correct 1908 ms 90540 KB Output is correct
36 Correct 2515 ms 114716 KB Output is correct
37 Correct 1529 ms 88988 KB Output is correct
38 Correct 1693 ms 105228 KB Output is correct
39 Correct 1482 ms 88924 KB Output is correct
40 Correct 1674 ms 105208 KB Output is correct
41 Correct 1447 ms 89020 KB Output is correct
42 Correct 1676 ms 105252 KB Output is correct
43 Correct 922 ms 56348 KB Output is correct
44 Correct 710 ms 42396 KB Output is correct
45 Correct 730 ms 47956 KB Output is correct
46 Correct 764 ms 48908 KB Output is correct
47 Correct 934 ms 51828 KB Output is correct
48 Correct 1519 ms 86544 KB Output is correct
49 Correct 585 ms 40492 KB Output is correct
50 Correct 555 ms 40568 KB Output is correct
51 Correct 685 ms 40448 KB Output is correct
52 Correct 675 ms 40460 KB Output is correct
53 Correct 560 ms 40508 KB Output is correct
54 Correct 682 ms 40548 KB Output is correct