이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "lib2249.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
int lowbit(int x){return x&-x;}
int bit[500005];
void upd(int pl,int val){
while(pl<=500000){
bit[pl]+=val;
pl+=lowbit(pl);
}
}
int qsum(int pl){
int ret=0;
while(pl){
ret+=bit[pl];
pl-=lowbit(pl);
}
return ret;
}
int n;int Q;
string ts;
int ar[500005];
string typs[500005];
set<pair<int,int>>seg;
struct cdq{
int t;int x;int y;
int val;int id;
};
bool cmp(cdq i,cdq j){
if(i.t<j.t){return 1;}
if(i.t>j.t){return 0;}
}
vector<cdq>pts;
void ptins(int a,int b,int c,int d,int vl,int t){
pts.push_back({t,c,d,vl,0});
pts.push_back({t,a-1,b-1,vl,0});
pts.push_back({t,c,b-1,-vl,0});
pts.push_back({t,a-1,d,-vl,0});
}
void mrg(int a,int b,int vl,int t){
auto rit=seg.upper_bound({a,9999999});
auto lit=prev(rit);
int ll=(*lit).first;int lr=(*lit).second;
int rl=(*rit).first;int rr=(*rit).second;
ptins(ll,rl,lr,rr,vl,t);
seg.erase(rit);
seg.erase(lit);
seg.insert({ll,rr});
}
signed main(){
cin>>n>>Q;
cin>>ts;
for(int i=1;i<=n;i++){
ar[i]=ts[i-1]-'0';
}
for(int i=1;i<=n;i++){
if(ar[i]==0){continue;}
int l=i;
seg.insert({i,i});
while(i+1<=n&&ar[i+1]==1){
seg.insert({i+1,i+1});
mrg(i,i+1,Q+1,0);
}
}
for(int i=1;i<=Q;i++){
cin>>typs[i];
if(typs[i]=="toggle"){
int pl;
cin>>pl;
ar[pl]^=1;
if(ar[pl]==1){
seg.insert({pl,pl});
if(pl>=2&&ar[pl-1]==1){
mrg(pl-1,pl,Q+1-i,i);
}
if(pl<=n-1&&ar[pl+1]==1){
mrg(pl,pl+1,Q+1-i,i);
}
}else{
auto it=seg.upper_bound({pl,9999999});
it=prev(it);
int l=(*it).first;int r=(*it).second;
seg.erase(it);
if(l<pl){
ptins(l,pl,pl-1,r,-(Q+1-i),i);
}
if(r>pl){
ptins(pl,pl+1,pl,r,-(Q+1-i),i);
}
if(r>pl){
seg.insert({pl+1,r});
}
if(l<pl){
seg.insert({l,pl-1});
}
}
}else{
int a;int b;
cin>>a>>b;
pts.push_back({i,a,b,0,i});
}
}
}
/*
void op(set<int>st){
for(auto it=st.begin();it!=st.end();it++){
cout<<*it<<" ";
}cout<<endl;
}
*/
컴파일 시 표준 에러 (stderr) 메시지
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:79:9: warning: unused variable 'l' [-Wunused-variable]
79 | int l=i;
| ^
street_lamps.cpp: In function 'bool cmp(cdq, cdq)':
street_lamps.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
41 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |