結果

問題 No.3330 Many Point Chmax Range Sum
ユーザー 👑 kmjp
提出日時 2025-11-25 23:57:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,311 bytes
コンパイル時間 2,204 ms
コンパイル使用メモリ 208,352 KB
実行使用メモリ 24,992 KB
最終ジャッジ日時 2025-11-25 23:57:23
合計ジャッジ時間 14,333 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other WA * 5 TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<ll,20> bt;

int N,K,Q;
int A[151515],M[151515];
int P[151515],X[151515];
int L[151515],R[151515],D[151515],U[151515];

const int DI=400;
vector<pair<int,int>> ev[DI];
ll ret[151515];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>Q;
	FOR(i,N) {
		cin>>A[i];
		bt.add(i,A[i]);
	}
	FOR(i,K) {
		cin>>P[i]>>X[i];
		P[i]--;
	}
	FOR(i,Q) {
		cin>>L[i]>>R[i]>>D[i]>>U[i];
		L[i]--,D[i]--;
		if(R[i]-L[i]<DI+10) {
			for(j=L[i];j<R[i];j++) {
				x=bt(P[j])-bt(P[j]-1);
				if(x<X[j]) {
					bt.add(P[j],X[j]-x);
				}
				ret[i]=bt(U[i]-1)-bt(D[i]-1);
			}
			for(j=L[i];j<R[i];j++) {
				x=bt(P[j])-bt(P[j]-1);
				if(x>A[j]) bt.add(j,A[j]-x);
			}
		}
		else {
			ev[L[i]/DI].push_back({R[i],i});
		}
	}
	FOR(i,DI) {
		FOR(j,N) bt.add(j,-bt(j));
		FOR(j,N) {
			bt.add(j,A[j]);
			M[j]=A[j];
		}
		sort(ALL(ev[i]));
		int CR=(i+1)*DI;
		FORR2(r,x,ev[i]) {
			int TR=R[x];
			while(CR<TR) {
				if(X[CR]>M[P[CR]]) {
					bt.add(P[CR],X[CR]-M[P[CR]]);
					M[P[CR]]=X[CR];
				}
				CR++;
			}
			for(j=L[x];j<(i+1)*DI;j++) {
				y=bt(P[j])-bt(P[j]-1);
				if(y<X[j]) bt.add(P[j],X[j]-y);
			}
			ret[x]=bt(U[x]-1)-bt(D[x]-1);
			for(j=L[x];j<(i+1)*DI;j++) {
				y=bt(P[j])-bt(P[j]-1);
				if(y>M[P[j]]) bt.add(P[j],M[P[j]]-y);
			}
			
		}
		
	}
	FOR(i,Q) cout<<ret[i]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0