QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#243804#7020. The Kouga Ninja Scrollsyiyiyi#AC ✓2096ms53648kbC++172.8kb2023-11-08 17:36:312023-11-08 17:36:32

Judging History

你现在查看的是最新测评结果

  • [2023-11-08 17:36:32]
  • 评测
  • 测评结果:AC
  • 用时:2096ms
  • 内存:53648kb
  • [2023-11-08 17:36:31]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(int i=(s);i>=(t);i--)
using namespace std;
ll ci(){ ll x; scanf("%lld", &x); return x; }

enum{N=500023};

struct dt{ ll mx,p,mx2,p2; };
dt NIL = (dt){-(ll)1e18,0,-(ll)1e18,0};
dt operator+(const dt&a,const dt&b){
	pair<ll,ll> d[4] = {
		{a.mx,a.p},
		{b.mx,b.p},
		{a.mx2,a.p2},
		{b.mx2,b.p2},
	};
		//printf("line %d: %lld %lld %lld %lld %lld %lld %lld %lld \n", __LINE__,
		//	a.mx,a.p, b.mx,b.p, a.mx2,a.p2, b.mx2,b.p2);
	sort(d,d+4,greater<pair<ll,ll>>());
	if( d[0].second!=d[1].second ) return {d[0].first, d[0].second, d[1].first, d[1].second};
	return {d[0].first, d[0].second, d[2].first, d[2].second};
}
class SEG{
private:
	dt tr[N*4];
	#define lc(x) ((x)<<1)
	#define rc(x) ((x)<<1|1)
	void update(int x){
		tr[x] = tr[lc(x)] + tr[rc(x)];
	}
	void add(int x,int l,int r,int ql,int qr,dt k){
		if( ql<=l && r<=qr ) return tr[x] = k, void();
		int mid = (l+r)/2;
		( ql<=mid ? add(lc(x), l,mid ,ql,qr,k) : void());
		( mid< qr ? add(rc(x),mid+1,r,ql,qr,k) : void());
		update(x);
	}
	dt query(int x,int l,int r,int ql,int qr){
		if( ql<=l && r<=qr ) return tr[x];
		int mid = (l+r)/2;
		return ( ql<=mid ? query(lc(x), l,mid ,ql,qr) : NIL)
			  +( mid< qr ? query(rc(x),mid+1,r,ql,qr) : NIL);
	}
	void build(int x,int l,int r){
		tr[x]=NIL;
		if( l==r ) return ;
		int mid = (l+r)/2;
		build(lc(x), l,mid );
		build(rc(x),mid+1,r);
	}
	int n;
public:
	void init(int n0){
		n = n0;
		build(1,1,n);
	}
	void add(int p,dt k){
		add(1,1,n,p,p,k);
	}
	dt query(int l,int r){
		if( l>r ) return NIL;
		return query(1,1,n,l,r);
	}
};

SEG seg[4];

void Add(int p, int x, int y, int c){
		//printf("line %d: %d %d %d %d\n", __LINE__, p,x,y,c);
	seg[0].add(p,{x+y,c,-(ll)1e18,0});
	seg[1].add(p,{-x+y,c,-(ll)1e18,0});
	seg[2].add(p,{-x-y,c,-(ll)1e18,0});
	seg[3].add(p,{x-y,c,-(ll)1e18,0});
}
ll Query(int l, int r){
	if( l>r ) return 0;
	ll ans = 0;
	rep(t,0,1){
		dt x = seg[t].query(l,r);
		dt y = seg[t+2].query(l,r);
		if( x.p2==0 ) return 0;
		if( x.p!=y.p ) ans = max(ans, abs(x.mx+y.mx));
		else ans = max(ans, max(abs(x.mx2+y.mx), abs(x.mx+y.mx2)));
	}
	return ans;
}

ll x[N], y[N], c[N];
 
signed main(){
	int T = ci();
	rep(cases,1,T){
		printf("Case #%d:\n", cases);
		int n = ci(), q = ci();
		rep(i,0,3) seg[i].init(n);
		rep(i,1,n) x[i] = ci(), y[i] = ci(), c[i] = ci(), Add(i, x[i], y[i], c[i]);
		while( q-- ){
			int opt = ci();
			if( opt==1 ){
				int i = ci(), x0 = ci(), y0 = ci();
				Add(i, x[i]+=x0,y[i]+=y0,c[i]);
			}else if( opt==2 ){
				int i = ci(), c0 = ci();
				Add(i, x[i],y[i],c[i]=c0);
			}else{
				int l = ci(), r = ci();
				printf("%lld\n", Query(l,r));
			}
		}
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 16196kb

input:

1
2 8
0 0 1
1 1 2
3 1 2
1 1 1 1
3 1 2
1 1 1 1
2 1 2
3 1 2
2 1 1
3 1 2

output:

Case #1:
2
0
0
2

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 2096ms
memory: 53648kb

input:

60
500 500
869676911 -813404481 62
-945322435 46069424 18
-178313683 -431754291 62
365370429 989841420 403
581432447 750507267 482
151389216 29933356 18
-526811063 -170809743 105
862783905 920464530 91
343253321 -871223893 192
403379791 828503986 91
775506325 -370049275 192
533550283 -577541037 482
...

output:

Case #1:
3685787673
3468859321
3333691523
3468859321
3333691523
3333691523
3961865677
4160346448
3515366597
4160346448
3751993658
4096942446
4554140217
4554140217
2383169926
3685167062
3617781469
4554140217
3173729474
4625859024
3707466685
4554140217
4753589768
3960896897
4554140217
4554140217
45541...

result:

ok 216379 lines