結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー 沙耶花沙耶花
提出日時 2022-10-14 21:54:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,330 ms / 6,000 ms
コード長 1,758 bytes
コンパイル時間 7,403 ms
コンパイル使用メモリ 275,080 KB
実行使用メモリ 179,316 KB
最終ジャッジ日時 2023-09-08 21:02:25
合計ジャッジ時間 80,603 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 970 ms
97,224 KB
testcase_04 AC 1,614 ms
130,820 KB
testcase_05 AC 899 ms
88,700 KB
testcase_06 AC 1,594 ms
121,632 KB
testcase_07 AC 1,650 ms
140,960 KB
testcase_08 AC 1,537 ms
126,040 KB
testcase_09 AC 766 ms
77,648 KB
testcase_10 AC 694 ms
68,808 KB
testcase_11 AC 1,122 ms
97,008 KB
testcase_12 AC 1,127 ms
98,280 KB
testcase_13 AC 783 ms
73,704 KB
testcase_14 AC 832 ms
57,052 KB
testcase_15 AC 1,877 ms
150,896 KB
testcase_16 AC 1,475 ms
133,528 KB
testcase_17 AC 534 ms
47,596 KB
testcase_18 AC 2,309 ms
177,672 KB
testcase_19 AC 2,327 ms
178,592 KB
testcase_20 AC 2,291 ms
178,028 KB
testcase_21 AC 2,269 ms
178,444 KB
testcase_22 AC 2,264 ms
177,956 KB
testcase_23 AC 2,275 ms
177,832 KB
testcase_24 AC 2,268 ms
177,384 KB
testcase_25 AC 2,257 ms
177,900 KB
testcase_26 AC 2,241 ms
178,976 KB
testcase_27 AC 2,306 ms
177,608 KB
testcase_28 AC 2,330 ms
179,316 KB
testcase_29 AC 2,329 ms
177,452 KB
testcase_30 AC 2,285 ms
178,608 KB
testcase_31 AC 2,251 ms
177,676 KB
testcase_32 AC 2,249 ms
178,368 KB
testcase_33 AC 2,173 ms
178,064 KB
testcase_34 AC 2,245 ms
178,012 KB
testcase_35 AC 2,186 ms
178,784 KB
testcase_36 AC 2,236 ms
178,760 KB
testcase_37 AC 2,244 ms
178,428 KB
testcase_38 AC 671 ms
61,472 KB
testcase_39 AC 820 ms
59,136 KB
testcase_40 AC 642 ms
23,428 KB
testcase_41 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 2000000000000000001
using P = pair<long long,long long>;

P op(P a,P b){
	auto ret = make_pair(0,0);
	ret.first = a.first + b.first;
	ret.second = a.second + b.second;
	return ret;
}

P e(){
	return make_pair(0LL,0LL);
}

P mapping(P a,long long b){
	a.first += b * a.second;
	return a;
}

long long composition(long long a,long long b){
	return a+b;
}

long long id(){
	return 0;
}

int main(){
	
	int n;
	cin>>n;
	
	map<long long,vector<int>> Add,Del;// Add(200005),Del(200005);
	fenwick_tree<long long> S(n+1),C(n+1);
	vector<long long> a(n),t(n);
	vector<long long> ts;
	rep(i,n){
	
		cin>>a[i]>>t[i];
		S.add(i,a[i]);
		
		Add[t[i]].push_back(i);
		
		
		Del[t[i]+a[i]].push_back(i);
		ts.push_back(t[i]);
		ts.push_back(t[i]+a[i]);
	}
	int q;
	cin>>q;
	vector<int> d(q),l(q),r(q);
	//vector<vector<int>> Qs(200005);
	map<long long,vector<int>> Qs;
	
	rep(i,q){
		cin>>d[i]>>l[i]>>r[i];
		l[i]--;
		Qs[d[i]].push_back(i);
		ts.push_back(d[i]);
	}
	sort(ts.begin(),ts.end());
	ts.erase(unique(ts.begin(),ts.end()),ts.end());
	vector<long long> ans(q);
	
	rep(i,ts.size()){
		rep(j,Add[ts[i]].size()){
			int ii = Add[ts[i]][j];
			S.add(ii,ts[i]-1);
			C.add(ii,1);
		}
		rep(j,Del[ts[i]].size()){
			int ii = Del[ts[i]][j];
			S.add(ii,-S.sum(ii,ii+1));
			C.add(ii,-C.sum(ii,ii+1));
		}
		rep(j,Qs[ts[i]].size()){
			int ii = Qs[ts[i]][j];
			long long tt = 0;
			tt += S.sum(l[ii],r[ii]);
			tt -= C.sum(l[ii],r[ii]) * (long long)ts[i];
			ans[ii] = tt;
		}
		
		
	}
	
	rep(i,q){
		cout<<ans[i]<<endl;
	}
	
	
	return 0;
}
0