标签:col read fir define tchar space pos color 题解
一眼看过去就是ODT瞎搞,题解区一堆线段树巨长的emmm
#include <bits/stdc++.h> using namespace std; #define ll long long #define re register #define pb push_back #define fi first const int N=1e6+10; void read(int &a) { a=0;int d=1;char ch; while(ch=getchar(),ch>‘9‘||ch<‘0‘) if(ch==‘-‘) d=-1; a=ch^48; while(ch=getchar(),ch>=‘0‘&&ch<=‘9‘) a=(a<<3)+(a<<1)+(ch^48); a*=d; } struct note { int l,r; mutable bool v; note(int L,int R=-1,int V=0){l=L,r=R,v=V;} bool operator < (const note &x) const { return l<x.l; } }; set <note> s; set <note> :: iterator split(int pos) { auto it=s.lower_bound(note(pos)); if(it!=s.end()&&it->l==pos) return it; it--; if(it->r<pos) return s.end(); int L=it->l,R=it->r; bool V=it->v; s.erase(it); s.insert(note(L,pos-1,V)); return s.insert(note(pos,R,V)).fi; } void ass(int l,int r,int val) { auto it2=split(r+1),it1=split(l); s.erase(it1,it2); s.insert(note(l,r,val)); } void rev(int l,int r) { auto it2=split(r+1),it1=split(l); for(;it1!=it2;it1++) it1->v^=1; } int query1(int l,int r) { int ans=0; auto it2=split(r+1),it1=split(l); for(;it1!=it2;it1++) ans+=it1->v?it1->r-it1->l+1:0; return ans; } int query2(int l,int r) { int ans=0,sum=0; auto it2=split(r+1),it1=split(l); for(;it1!=it2;it1++) { if(it1->v==0) ans=max(ans,sum),sum=0; else sum+=it1->r-it1->l+1; } ans=max(ans,sum); return ans; } int main() { int n,m; read(n),read(m); for(re int i=0,x;i<n;i++) read(x),s.insert(note(i,i,x)); s.insert(note(n,n,0)); for(re int i=1,op,a,b;i<=m;i++) { read(op),read(a),read(b); if(op==0) ass(a,b,0); else if(op==1) ass(a,b,1); else if(op==2) rev(a,b); else if(op==3) printf("%d\n",query1(a,b)); else printf("%d\n",query2(a,b)); } return 0; }
标签:col read fir define tchar space pos color 题解
原文地址:https://www.cnblogs.com/acm1ruoji/p/11853422.html