卡了一下午常数也没过 TLE.....
过几年再来调试试.
E. Colorful Operations
TLE Code:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#define endl '\n'
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef unsigned long long ull;
const int M=2010;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int N=1e6+10;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
char In[1 << 20], *ss = In, *tt = In;
#define getchar() (ss == tt && (tt = (ss = In) + fread(In, 1, 1 << 20, stdin), tt == ss) ? EOF : *ss++)
int read (char ch = 0) {
register ll x = 0, f = 1;
while (ch < '0' || ch > '9') f = ch == '-' ? -1 : 1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
return x * f;
}
char getch (char ch = 0) {
while (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z') ch = getchar();
return ch;
}
inline void write(ll x) {
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10ll);
putchar(x%10+48);
}
struct node{
int l,r;
ll val;
int col;
int add1;
ll add2;
}tr[N*4];
inline void build(int u,int l,int r)
{
if(l==r)tr[u]={l,r,0,1,1,0};
else
{
tr[u]={l,r,-1,1,1,0};
int mid=l+r>>1;
build(u<<1,l,mid);
build(u<<1|1,mid+1,r);
}
}
inline void pushdown1(int u)//向下传递新的颜色
{
register auto &root=tr[u],&left=tr[u<<1],&right=tr[u<<1|1];
if(root.add1)
{
left.add1=root.add1,left.col=root.add1;
right.add1=root.add1,right.col=root.add1;
root.add1=0;//置成非法值
}
}
inline void pushdown2(int u)
{
register auto &root=tr[u],&left=tr[u<<1],&right=tr[u<<1|1];
if(root.add2)
{
left.add2+=root.add2,left.val+=root.add2;
right.add2+=root.add2,right.val+=root.add2;
root.add2=0;
}
}
inline void Color(int u,int l,int r,int x)
{
if(tr[u].l>=l&&tr[u].r<=r)
{
tr[u].col=x;
tr[u].add1=x;
}
else//必须分裂
{
if(tr[u].col==x)return ;//不需要改
pushdown1(u);
int mid=tr[u].l+tr[u].r>>1;
if(l<=mid)Color(u<<1,l,r,x);
if(r>mid)Color(u<<1|1,l,r,x);
tr[u].col=-1;//等价于pushup
}
}
inline void Add(int u,int c,int x)
{
register auto &left=tr[u<<1],&right=tr[u<<1|1];
if(tr[u].col==-1)
{
if(left.col==-1||left.col==c)Add(u<<1,c,x);
if(right.col==-1||right.col==c)Add(u<<1|1,c,x);
}else if(tr[u].col==c)
{
if(tr[u].l==tr[u].r)tr[u].val+=x;//如果是一个值就直接计算即可
else tr[u].add2+=x;
}
}
ll query(int u,int l,int r)
{
if(l==tr[u].l&&r==tr[u].r)return tr[u].val;
else//必须分裂
{
pushdown2(u);
pushdown1(u);
int mid=tr[u].l+tr[u].r>>1;
if(l<=mid)return query(u<<1,l,r);
else return query(u<<1|1,l,r);
}
}
void solve()
{
int n,q;
n=read(),q=read();
build(1,1,n);
while(q--)
{
char s[2] = {};
s[0] = getch();
if(s[0]=='C')
{
register int l=read(),r=read(),c=read();
Color(1,l,r,c);//区间修改
}else if(s[0]=='A')
{
register int c=read();
int x=read();
Add(1,c,x);//基于操作一的区间修改
}else
{
register int x=read();
write(query(1,x,x));
putchar('\n');
}
}
return ;
}
int main()
{
freopen("test.in","r",stdin);
solve();
return 0;
}
这调试确实是挺麻烦的