QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104262#186. Street Lampsfzj20070 114ms5768kbC++143.2kb2023-05-09 21:03:342023-05-09 21:03:34

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-09 21:03:34]
  • 评测
  • 测评结果:0
  • 用时:114ms
  • 内存:5768kb
  • [2023-05-09 21:03:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace IO{
	template<typename T>inline bool read(T &x){
		x=0;
		char ch=getchar();
		bool flag=0,ret=0;
		while(ch<'0'||ch>'9') flag=flag||(ch=='-'),ch=getchar();
		while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(),ret=1;
		x=flag?-x:x;
        return ret;
	}
	template<typename T,typename ...Args>inline bool read(T& a,Args& ...args){
	    return read(a)&&read(args...);
	}
	template<typename T>void prt(T x){
		if(x>9) prt(x/10);
		putchar(x%10+'0');
	}
	template<typename T>inline void put(T x){
		if(x<0) putchar('-'),x=-x;
		prt(x);
	}
	template<typename T>inline void put(char ch,T x){
		if(x<0) putchar('-'),x=-x;
		prt(x);
		putchar(ch);
	}
	template<typename T,typename ...Args>inline void put(T a,Args ...args){
	    put(a);
		put(args...);
	}
	template<typename T,typename ...Args>inline void put(const char ch,T a,Args ...args){
	    put(ch,a);
		put(ch,args...);
	}
	inline void put(string s){
		for(int i=0,sz=s.length();i<sz;i++) putchar(s[i]);
	}
	inline void put(const char* s){
		for(int i=0,sz=strlen(s);i<sz;i++) putchar(s[i]);
	}
	inline int getch(){
		char ch=getchar();
		while(ch!='0'&&ch!='1') ch=getchar();
		return ch-'0';
	}
	inline int getc(){
		char ch=getchar();
		while(ch!='q'&&ch!='t') ch=getchar();
		return ch=='q';
	}
}
using namespace IO;
#define N 300005
#define ll long long
int n,m,idx,w[N],rt[N],ls[N*60],rs[N*60];
ll t[N*60];
#define lc(x) ls[x]
#define rc(x) rs[x]
inline void Update(int &x,int l,int r,int ql,int qr,int val){
	if(!x) x=++idx;
	if(ql<=l&&qr>=r) return t[x]+=val,void();
	int mid=l+r>>1;
	if(ql<=mid) Update(lc(x),l,mid,ql,qr,val);
	if(qr>mid) Update(rc(x),mid+1,r,ql,qr,val);
}
inline ll Query(int x,int l,int r,int pos){
	if(!x) return 0;
	if(l==r) return t[x];
	int mid=l+r>>1;
	ll res=t[x];
	if(pos<=mid) res+=Query(lc(x),l,mid,pos);
	else res+=Query(rc(x),mid+1,r,pos);
	return res;
}
#undef lc
#undef rc
#define lowbit(x) (x&-x)
inline void update(int x,int l,int r,int v){
	if(l>r) return;
	for(;x<=n;x+=lowbit(x)) Update(rt[x],1,n,l,r,v);
}
inline int query(int x,int y){
	ll res=0;
	for(;x;x^=lowbit(x)) res+=Query(rt[x],1,n,y);
	return res;
}
#undef lowbit
set<pair<int,int> >s;
int main(){
	read(n,m);
	for(int i=1;i<=n;i++) w[i]=getch();
	for(int i=1;i<=n;i++){
		if(!w[i]) continue;
		int j=i;
		while(j<=n&&w[j]) j++;
		s.insert(make_pair(i,j-1));
		i=j-1;
	}
	for(int i=1,x,y;i<=m;i++){
		if(getc()){
			read(x,y);
			int ans=query(x,y-1);
			auto it=--s.lower_bound(make_pair(x+1,0));
			if(it->first<=x&&it->second>=y-1) ans+=i;
			put('\n',ans);
		}else{
			read(x);
			if(w[x]){
				auto it=--s.lower_bound(make_pair(x+1,0));
				int l=it->first,r=it->second;
				s.erase(it);
				if(l!=x) s.insert(make_pair(l,x-1));
				if(r!=x) s.insert(make_pair(x+1,r));
				update(l,x,r,i),update(x+1,x,r,-i);
			}else{
				int l=x,r=x;
				auto itl=s.lower_bound(make_pair(x+1,0)),itr=itl;
				if(itl!=s.begin()) itl--,l=itl->second==x-1?itl->first:l;
				if(itr!=s.end()) r=itr->first==x+1?itr->second:r;
				update(l,x,r,-i),update(r+1,x,r,i);
				if(l!=x) s.erase(itl);
				if(r!=x) s.erase(itr);
				s.insert(make_pair(l,r));		
			} 
			w[x]^=1;
		}
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 2ms
memory: 5340kb

input:

5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6

output:

1
2
0
0
1
2

result:

ok 6 lines

Test #2:

score: -20
Wrong Answer
time: 2ms
memory: 5348kb

input:

5 50
01001
query 1 6
toggle 3
toggle 3
toggle 2
toggle 3
toggle 2
toggle 4
query 2 6
query 2 3
query 1 3
query 3 5
toggle 3
query 2 6
query 1 5
query 2 3
query 3 6
toggle 5
toggle 1
toggle 2
toggle 4
query 1 6
query 4 5
toggle 3
query 5 6
toggle 2
query 4 6
toggle 5
toggle 5
toggle 2
query 4 5
query...

output:

0
1
7
0
4
5
0
13
5
0
13
10
10
13
5
5
6
-41
0
10
0
5
0
5
6

result:

wrong answer 12th lines differ - expected: '17', found: '10'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 114ms
memory: 3496kb

input:

100 300000
1100100000000101010010100111010001100010001100111101000010111110001101101110100100100110101010110010
query 13 14
query 42 43
toggle 64
query 78 79
toggle 85
query 35 36
toggle 35
query 4 5
toggle 5
query 4 5
query 42 43
query 35 36
query 13 14
query 14 15
toggle 15
toggle 31
query 20 21
q...

output:

0
0
0
6
0
0
0
7
0
14
0
18
0
0
21
0
26
0
0
12
38
15
16
44
0
22
20
50
28
0
55
52
56
0
35
31
70
-14
7
4
0
0
51
83
-1
90
44
0
95
97
0
70
0
34
26
8
46
20
109
88
20
109
108
0
0
28
0
45
114
-83
35
142
53
146
0
8
0
84
0
0
-304
0
164
0
100
0
33
-65
105
151
178
180
-195
133
-49
46
0
197
23
0
200
0
141
206
208...

result:

wrong answer 20th lines differ - expected: '36', found: '12'

Subtask #3:

score: 0
Wrong Answer

Test #17:

score: 20
Accepted
time: 4ms
memory: 5768kb

input:

1000 1003
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0
0
0

result:

ok 3 lines

Test #18:

score: -20
Wrong Answer
time: 3ms
memory: 3696kb

input:

1000 1003
00100001101000000001000001001000100010000010010010001001001010001010101100010001000010101100000001001111000001110000010110100000100110001000000101001110000001110001000100000011001110000011010100101000000010100110100010000000110000111100100000011000100010010100000000100000000010001001110101...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 302nd lines differ - expected: '2', found: '-998'

Subtask #4:

score: 0
Wrong Answer

Test #30:

score: 20
Accepted
time: 2ms
memory: 5400kb

input:

1000 1003
10111011001010101101100010101100100010100110001000000001001100111110101100110100010001111101101100110111110100011000111101100100000110110010101011101001101110111100010100100000110001010001111101001010100101011111010000001110111110001011010111101100000001001110101110011111000101101100011010...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 991 lines

Test #31:

score: 0
Accepted
time: 1ms
memory: 3508kb

input:

1000 1003
01000000111001001110011100111111110011010010110000100010101101101011100011010100100100110101110101010111011100110100110000001010110001011011011010001001101000111011001000000001001100101100010101011101000000101110111011011101100001011110111011001010011101000110100011000101011101000110001011...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 701 lines

Test #32:

score: -20
Wrong Answer
time: 3ms
memory: 5716kb

input:

1000 1003
00010001110110110000001111110000010011011011100111101001011010000111111110001111010101111011100100101000010111101111100011000111001111011011011101000101100000011101001001111110011000100011000001010001011000000010101001101111101111111101011101101000110010110111010111111001101000000100011100...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 271st lines differ - expected: '693', found: '538'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%