QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104259 | #186. Street Lamps | fzj2007 | 0 | 3ms | 5728kb | C++14 | 3.2kb | 2023-05-09 21:00:49 | 2023-05-09 21:00:50 |
Judging History
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));
}
}
}
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: 3300kb
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: 3296kb
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 0 4 0 4 0 0 4 9 0 -5 10 10 -20 10 2 0 -156 0 0 0 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '1', found: '0'
Subtask #2:
score: 0
Dangerous Syscalls
Test #9:
score: 0
Dangerous Syscalls
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: 3ms
memory: 3756kb
input:
1000 1003 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
0 0 0
result:
ok 3 lines
Test #18:
score: -20
Wrong Answer
time: 2ms
memory: 5728kb
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: 3ms
memory: 5288kb
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: -20
Wrong Answer
time: 2ms
memory: 3540kb
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:
wrong answer 550th lines differ - expected: '92', found: '255'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%