답안 #407123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407123 2021-05-18T14:19:25 Z amunduzbaev 가로등 (APIO19_street_lamps) C++14
0 / 100
5000 ms 15280 KB
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define lb lower_bound
#define ub upper_bound

const int N = 105;
const int M = 3e5+5;
const int mod = 1e9+7;

int n, m, k, a[M];
vector<array<int, 3>> tree[4*N];
string s;

int rr = 0, cnt = 0;
void find(int a, int b, int lx = 0, int rx = N, int x = 1){
	for(auto x : tree[x]){
		if(x[0] <= b && b <= x[1]) rr += x[2], cnt++;
	} int m = (lx + rx)>>1;
	if(lx == rx) return;
	if(a <= m) find(a, b, lx, m, x<<1);
	else find(a, b, m+1, rx, x<<1|1);
}

void add(int l, int r, array<int, 3> v, int lx = 0, int rx = N, int x = 1){
	if(lx > r || rx < l) return;
	if(lx >= l && rx <= r) { tree[x].pb(v); return; }
	int m = (lx + rx)>>1;
	add(l, r, v, lx, m, x<<1);
	add(l, r, v, m+1, rx, x<<1|1);
}

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>m>>s;
	
	set<int> ss;
	s = "$" + s;
	for(int i=1;i<=n;i++) {
		a[i] = s[i] - '0';
		if(!a[i]) ss.insert(i);
	} 
	
	for(int i=1;i<=n;i++){
		if(!a[i]) continue;
		int j = i;
		while(j <= n && a[j] == a[i]) j++;
		j--, add(i, j, {i, j, 0}), i = j;
	}
	
	for(int i=1;i<=m;i++){
		cin>>s;
		if(s == "query"){
			int a, b; cin>>a>>b; rr = 0, cnt = 0;
			find(a, b);
			if(cnt & 1) rr += i;
			cout<<rr<<"\n";
		} else {
			int m; cin>>m;
			if(a[m]){
				auto lx = ss.lb(m);
				auto rx = ss.ub(m);
				int l = (lx == ss.end() ? 0 : *lx > m ? 0 : *lx);
				int r = (rx == ss.begin() ? n + 1 : *--rx < m ? n + 1 : *rx);
				add(l, m, {m, r, i}), ss.insert(m);
			} else {
				ss.erase(m);
				auto lx = ss.lb(m);
				auto rx = ss.ub(m);
				int l = (lx == ss.end() ? 0 : *lx > m ? 0 : *lx);
				int r = (rx == ss.begin() ? n + 1 : *--rx < m ? n + 1 : *rx);
				add(l, m, {m, r, -i});	
			} a[m] ^= 1;
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5095 ms 15280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -