답안 #258155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258155 2020-08-05T12:51:48 Z _7_7_ 가로등 (APIO19_street_lamps) C++14
100 / 100
1291 ms 436664 KB
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
 
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 3e5 + 12;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;
 
int n, q, a, b, x, y;
char s[N], t[6];
set < int > pos;


struct ST {
	int tl, tr, sum;
	ST *l, *r;

	ST () {
		l = r = NULL;
	}
	
	ST (int lf, int rg) {
		tl = lf, tr = rg;
		sum = 0;
		l = r = NULL;
	}


	void update (int pos, int x) {
	   	sum += x;

		if (tl == tr)
			return;

		int tm = (tl + tr) >> 1;			
		if (pos <= tm) {
			if (!l)
				l = new ST(tl, tm);
			l->update(pos, x);
			return;
		}

		if (!r)
			r = new ST(tm + 1, tr);
		r->update(pos, x);
	}

	int get (int lf, int rg) {
		if (lf > rg || tl > rg || lf > tr)
			return 0;
		if (lf <= tl && tr <= rg)
			return sum;
	
		return (!l ? 0 : l->get(lf, rg)) + (!r ? 0 : r->get(lf, rg));
	}
} *T[N << 2];

void upd (int l, int r, int x, int y, int v = 1, int tl = 1, int tr = n) {
	if (l > r || tl > r || l > tr)
		return;
	
	if (l <= tl && tr <= r) {
		if (!T[v]) 
			T[v] = new ST(1, n); 
		T[v]->update(x, y);
		return;
	}

	int tm = (tl + tr) >> 1;
	upd(l, r, x, y, v << 1, tl, tm);
	upd(l, r, x, y, v << 1 | 1, tm + 1, tr);
}

int get (int x, int y, int v = 1, int tl = 1, int tr = n) {
	int res = 0;
	
	if (T[v])
		res += T[v]->get(1, y);
	
	if (tl == tr)
		return res;
	
	int tm = (tl + tr) >> 1;
	if (x <= tm)
		res += get(x, y, v << 1, tl, tm);
	else
		res += get(x, y, v << 1 | 1, tm + 1, tr);
	return res;
}


 
void update (int xa, int ya, int xb, int yb, int z) {
	upd(xa, xb, ya, z);
	if (yb < n)
		upd(xa, xb, yb + 1, -z);
}


main () {
	scanf("%d%d\n%s", &n, &q, s + 1);

	
	for (int i = 1; i <= n; ++i)
		if (s[i] == '0') 
			pos.insert(i);

	pos.insert(0);
	pos.insert(n + 1);
	
	
	for (int i = 1; i <= q; ++i) {
		scanf("\n%s%d", t, &a);
		if (t[0] == 't') {
			if (s[a] == '1') {
				auto it = pos.lower_bound(a);
				y = *it;
				--it;
				x = *it;

				++x, --y;

				update(x, a, a, y, i);
				pos.insert(a);
			} else {
				pos.erase(a);

				auto it = pos.lower_bound(a);
				y = *it;
				--it;
				x = *it;


				++x, --y;
				update(x, a, a, y, -i);
			}

			s[a] = '0' + '1' - s[a];
		} else {
			scanf("%d", &b);

			--b;

			int res = get(a, b);
			if (*pos.lower_bound(a) > b) 
				res += i; 			 
			printf("%d\n", res);
		}
	}

}

Compilation message

street_lamps.cpp:135:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:136:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d\n%s", &n, &q, s + 1);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:148:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("\n%s%d", t, &a);
   ~~~~~^~~~~~~~~~~~~~~~~
street_lamps.cpp:175:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &b);
    ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 1528 KB Output is correct
2 Correct 266 ms 2132 KB Output is correct
3 Correct 506 ms 11768 KB Output is correct
4 Correct 813 ms 174136 KB Output is correct
5 Correct 987 ms 273784 KB Output is correct
6 Correct 986 ms 196216 KB Output is correct
7 Correct 541 ms 15352 KB Output is correct
8 Correct 203 ms 2752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1280 KB Output is correct
2 Correct 2 ms 1152 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1291 ms 436664 KB Output is correct
6 Correct 1087 ms 368504 KB Output is correct
7 Correct 835 ms 277496 KB Output is correct
8 Correct 210 ms 8632 KB Output is correct
9 Correct 122 ms 4088 KB Output is correct
10 Correct 133 ms 4344 KB Output is correct
11 Correct 133 ms 4600 KB Output is correct
12 Correct 460 ms 21368 KB Output is correct
13 Correct 205 ms 8568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 2 ms 896 KB Output is correct
5 Correct 393 ms 17912 KB Output is correct
6 Correct 719 ms 122232 KB Output is correct
7 Correct 910 ms 195864 KB Output is correct
8 Correct 1089 ms 268304 KB Output is correct
9 Correct 251 ms 1528 KB Output is correct
10 Correct 205 ms 632 KB Output is correct
11 Correct 245 ms 1528 KB Output is correct
12 Correct 207 ms 632 KB Output is correct
13 Correct 257 ms 1528 KB Output is correct
14 Correct 203 ms 632 KB Output is correct
15 Correct 533 ms 15396 KB Output is correct
16 Correct 200 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 217 ms 1528 KB Output is correct
9 Correct 266 ms 2132 KB Output is correct
10 Correct 506 ms 11768 KB Output is correct
11 Correct 813 ms 174136 KB Output is correct
12 Correct 987 ms 273784 KB Output is correct
13 Correct 986 ms 196216 KB Output is correct
14 Correct 541 ms 15352 KB Output is correct
15 Correct 203 ms 2752 KB Output is correct
16 Correct 2 ms 1280 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1291 ms 436664 KB Output is correct
21 Correct 1087 ms 368504 KB Output is correct
22 Correct 835 ms 277496 KB Output is correct
23 Correct 210 ms 8632 KB Output is correct
24 Correct 122 ms 4088 KB Output is correct
25 Correct 133 ms 4344 KB Output is correct
26 Correct 133 ms 4600 KB Output is correct
27 Correct 460 ms 21368 KB Output is correct
28 Correct 205 ms 8568 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 640 KB Output is correct
31 Correct 2 ms 768 KB Output is correct
32 Correct 2 ms 896 KB Output is correct
33 Correct 393 ms 17912 KB Output is correct
34 Correct 719 ms 122232 KB Output is correct
35 Correct 910 ms 195864 KB Output is correct
36 Correct 1089 ms 268304 KB Output is correct
37 Correct 251 ms 1528 KB Output is correct
38 Correct 205 ms 632 KB Output is correct
39 Correct 245 ms 1528 KB Output is correct
40 Correct 207 ms 632 KB Output is correct
41 Correct 257 ms 1528 KB Output is correct
42 Correct 203 ms 632 KB Output is correct
43 Correct 533 ms 15396 KB Output is correct
44 Correct 200 ms 2680 KB Output is correct
45 Correct 100 ms 2808 KB Output is correct
46 Correct 143 ms 2936 KB Output is correct
47 Correct 446 ms 87272 KB Output is correct
48 Correct 820 ms 179116 KB Output is correct
49 Correct 138 ms 4472 KB Output is correct
50 Correct 135 ms 4472 KB Output is correct
51 Correct 137 ms 4728 KB Output is correct
52 Correct 136 ms 4856 KB Output is correct
53 Correct 137 ms 4856 KB Output is correct
54 Correct 143 ms 4892 KB Output is correct