QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#500244#186. Street LampsRafi220 2ms5768kbC++202.3kb2024-08-01 04:53:232024-08-01 04:53:23

Judging History

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

  • [2024-08-01 04:53:23]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:5768kb
  • [2024-08-01 04:53:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
int inf=1000000007;
ll infl=1000000000000000007;
ll mod=1000000007;

const int N=300007;

bool is[N];
int ans[N];
vector<pair<pair<int,int>,int>>add[N];

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	int n,q;
	cin>>n>>q>>s;
	set<pair<pair<int,int>,int>>S;
	int it=1;
	FOR(i,1,n)
	{
		is[i]=s[i-1]-'0';
		if(s[i-1]=='0')
		{
			if(it<i)
			{
				S.insert({{it,i-1},0});
				it=i+1;
			}
		}
	}
	S.insert({{-inf,-inf},0});
	S.insert({{inf,inf},0});
	if(it<=n) S.insert({{it,n},0});
	debug(S);
	FOR(i,1,q)
	{
		string tt;
		cin>>tt;
		if(tt[0]=='t')
		{
			int x;
			cin>>x;
			if(is[x])
			{
				pair<pair<int,int>,int>t=*--S.upper_bound({{x,inf},inf});
				add[i].pb({t.st,i-t.nd});
				S.erase(t);
				if(t.st.st<x) S.insert({{t.st.st,x-1},i});
				if(t.st.nd>x) S.insert({{x+1,t.st.nd},i});
			}
			else
			{
				int L=x,R=x;
				if(is[x-1])
				{
					pair<pair<int,int>,int>t=*--S.upper_bound({{x-1,inf},inf});
					L=t.st.st;
					add[i].pb({t.st,i-t.nd});
					S.erase(t);
				}
				if(is[x+1])
				{
					pair<pair<int,int>,int>t=*--S.upper_bound({{x+1,inf},inf});
					R=t.st.nd;
					add[i].pb({t.st,i-t.nd});
					S.erase(t);
				}
				S.insert({{L,R},i});
			}
			is[x]^=1;
			ans[i]=-1;
		}
		else
		{
			int l,r;
			cin>>l>>r;
			r--;
			pair<pair<int,int>,int>t=*--S.upper_bound({{l,inf},inf});
			if(t.st.st<=l&&t.st.nd>=r) ans[i]=i-t.nd;
			FOR(j,1,i-1)
			{
				debug(j,add[j]);
				for(auto [p,c]:add[j]) if(p.st<=l&&p.nd>=r) ans[i]+=c; 
			}
		}
	}
	FOR(i,1,q) if(ans[i]>=0) cout<<ans[i]<<endl;
	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: 1ms
memory: 5528kb

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: 0
Wrong Answer
time: 1ms
memory: 5672kb

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
4
4
5
0
13
5
0
20
17
17
20
5
5
10
24
0
10
0
5
0
5
7

result:

wrong answer 4th lines differ - expected: '0', found: '4'

Subtask #2:

score: 0
Time Limit Exceeded

Test #9:

score: 0
Time Limit Exceeded

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:


result:


Subtask #3:

score: 0
Wrong Answer

Test #17:

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

input:

1000 1003
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0
0
0

result:

ok 3 lines

Test #18:

score: 0
Wrong Answer
time: 2ms
memory: 5748kb

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 295th lines differ - expected: '46', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #30:

score: 0
Wrong Answer
time: 2ms
memory: 5684kb

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:

wrong answer 358th lines differ - expected: '0', found: '370'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%