結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー 👑 kmjpkmjp
提出日時 2022-10-14 23:29:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 551 ms / 6,000 ms
コード長 1,707 bytes
コンパイル時間 2,782 ms
コンパイル使用メモリ 207,488 KB
実行使用メモリ 29,720 KB
最終ジャッジ日時 2023-09-08 23:55:15
合計ジャッジ時間 24,914 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
21,916 KB
testcase_01 AC 5 ms
17,776 KB
testcase_02 AC 5 ms
21,868 KB
testcase_03 AC 176 ms
24,716 KB
testcase_04 AC 381 ms
26,912 KB
testcase_05 AC 183 ms
25,404 KB
testcase_06 AC 333 ms
26,216 KB
testcase_07 AC 359 ms
26,888 KB
testcase_08 AC 392 ms
26,572 KB
testcase_09 AC 149 ms
23,976 KB
testcase_10 AC 154 ms
24,068 KB
testcase_11 AC 288 ms
26,012 KB
testcase_12 AC 292 ms
25,592 KB
testcase_13 AC 185 ms
24,372 KB
testcase_14 AC 292 ms
24,740 KB
testcase_15 AC 441 ms
27,256 KB
testcase_16 AC 275 ms
26,108 KB
testcase_17 AC 192 ms
23,928 KB
testcase_18 AC 537 ms
28,288 KB
testcase_19 AC 532 ms
28,288 KB
testcase_20 AC 536 ms
29,212 KB
testcase_21 AC 531 ms
29,596 KB
testcase_22 AC 535 ms
29,240 KB
testcase_23 AC 545 ms
29,276 KB
testcase_24 AC 538 ms
29,496 KB
testcase_25 AC 534 ms
29,004 KB
testcase_26 AC 550 ms
27,812 KB
testcase_27 AC 541 ms
28,776 KB
testcase_28 AC 543 ms
28,288 KB
testcase_29 AC 547 ms
28,832 KB
testcase_30 AC 537 ms
29,672 KB
testcase_31 AC 551 ms
28,836 KB
testcase_32 AC 539 ms
28,996 KB
testcase_33 AC 513 ms
28,268 KB
testcase_34 AC 533 ms
29,508 KB
testcase_35 AC 517 ms
28,324 KB
testcase_36 AC 533 ms
29,720 KB
testcase_37 AC 509 ms
29,292 KB
testcase_38 AC 305 ms
25,060 KB
testcase_39 AC 339 ms
25,324 KB
testcase_40 AC 451 ms
28,404 KB
testcase_41 AC 5 ms
17,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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> AX,B;

int N;
ll A[202020],T[202020];
int Q;
ll D[202020],L[202020],R[202020],ret[202020];

vector<pair<int,int>> ev;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i]>>T[i];
		B.add(i,A[i]);
		if(A[i]) {
			ev.push_back({T[i],i});
			ev.push_back({T[i]+A[i],i});
		}
	}
	cin>>Q;
	FOR(i,Q) {
		cin>>D[i]>>L[i]>>R[i];
		L[i]--,R[i]--;
		ev.push_back({D[i],N+i});
	}
	sort(ALL(ev));
	FORR2(t,i,ev) {
		if(i<N) {
			if(t==T[i]) {
				B.add(i,T[i]-1);
				AX.add(i,-1);
			}
			else {
				B.add(i,-A[i]-T[i]+1);
				AX.add(i,1);
			}
		}
		else {
			i-=N;
			ret[i]=t*(AX(R[i])-AX(L[i]-1))+B(R[i])-B(L[i]-1);
		}
	}
	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