Submission #858480

#TimeUsernameProblemLanguageResultExecution timeMemory
8584808pete8Street Lamps (APIO19_street_lamps)C++14
20 / 100
1116 ms105784 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<limits.h> #include<cmath> #include<set> #include<algorithm> #include<bitset> #include<list> using namespace std; #define ll long long #define f first #define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define p push #define pb push_back #define fastio ios::sync_with_stdio(false);cin.tie(NULL); using namespace std; #define int long long const int mxn=3e5,mod=69,lg=42,root=80,inf=1e18; int n; bitset<mxn+10>on; struct seg{ int vmx[2*mxn+10],vmn[2*mxn+10]; void init(){for(int i=0;i<=2*mxn;i++)vmx[i]=vmn[i]=0;} void updatemx(int pos,int val){ pos+=n; vmx[pos]=val; for(;pos>0;pos>>=1)vmx[pos>>1]=max(vmx[pos],vmx[pos^1]); } int qrymx(int l,int r){ int ans=0; for(l+=n,r+=n;l<=r;l>>=1,r>>=1){ if(l&1)ans=max(ans,vmx[l++]); if(!(r&1))ans=max(ans,vmx[r--]); } return ans; } void updatemn(int pos,int val){ vmn[pos+=n]=val; for(;pos>0;pos>>=1)vmn[pos>>1]=max(vmn[pos],vmn[pos^1]); } int qrymn(int l,int r){ int ans=inf; for(l+=n,r+=n;l<=r;l>>=1,r>>=1){ if(l&1)ans=min(ans,vmn[l++]); if(!(r&1))ans=min(ans,vmn[r--]); } return ans; } }t;//pos qry mx struct fen{ vector<int>all_y[mxn+10],fwk[mxn+10]; int rank(int x,int y){return upper_bound(all(all_y[x]),y)-all_y[x].begin();} void init(vector<pii>v){ sort(all(v)); vector<int>cnt_y(mxn+10,0); for(auto i:v){ for(int j=i.f;j<=n;j+=(j&-j))++cnt_y[j]; } for(int i=0;i<=n;i++){ all_y[i].reserve(cnt_y[i]); fwk[i].resize(cnt_y[i]); } for(auto i:v)for(int j=i.f;j<=n;j+=(j&-j))all_y[j].pb(i.s); } void update(int x,int y2,int t){ for(;x<=n;x+=x&-x){ for (int y=rank(x,y2);y<=all_y[x].size();y+=y&-y)fwk[x][y-1]+=t; } } int qry(int x, int y2){ int ans=0; for (;x;x-=x&-x) for (int y=rank(x,y2);y;y-=y&-y)ans+=fwk[x][y-1]; return ans; } }f; pii bs(int pos){ int l=pos,r=n; int a=0,b=inf; while(l<=r){ int mid=l+(r-l)/2; if(t.qrymn(pos,mid))l=mid+1,a=max(a,mid); else r=mid-1; } l=0,r=pos; while(l<=r){ int mid=l+(r-l)/2; if(t.qrymn(mid,pos))r=mid-1,b=min(b,mid); else l=mid+1; } return {a,b}; } int32_t main(){ fastio int m;cin>>n>>m; string a;cin>>a; for(int i=0;i<n;i++){ if(a[i]=='0')t.updatemx(i+1,inf); else on[i+1]=true; t.updatemn(i+1,a[i]-'0'); } vector<pii>pass; vector<ppii>q; q.pb({0,{0,0}}); for(int i=1;i<=m;i++){ cin>>a; if(a[0]=='t'){ int x;cin>>x; q.pb({1,{x,-1}}); } else{ int l,r;cin>>l>>r; pass.pb({l,r}); q.pb({2,{l,r}}); } } f.init(pass); for(int i=1;i<=m;i++){//time if(q[i].f==1){ int x=q[i].s.f; if(on[x])t.updatemx(x,i),on[x]=false; else{ t.updatemn(x,1); t.updatemx(x,i); pii range=bs(x); int g=t.vmx[x+n],comp=0; if(g==inf)continue; else comp=i-g; if(comp==0)continue; f.update(range.f,range.s,comp); } } else{ int l=q[i].s.f,r=q[i].s.s; int g=t.qrymx(l,r-1); if(g==inf)g=0; else g=i-g; cout<<g+f.qry(l,r-1)<<'\n'; } } }

Compilation message (stderr)

street_lamps.cpp: In member function 'void fen::update(long long int, long long int, long long int)':
street_lamps.cpp:81:36: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |             for (int y=rank(x,y2);y<=all_y[x].size();y+=y&-y)fwk[x][y-1]+=t;
      |                                   ~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...