結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー StstoneStstone
提出日時 2022-10-17 11:21:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 304 ms / 6,000 ms
コード長 2,569 bytes
コンパイル時間 4,004 ms
コンパイル使用メモリ 237,192 KB
実行使用メモリ 34,316 KB
最終ジャッジ日時 2023-09-10 10:49:12
合計ジャッジ時間 25,059 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,668 KB
testcase_01 AC 2 ms
5,436 KB
testcase_02 AC 3 ms
5,416 KB
testcase_03 AC 138 ms
17,076 KB
testcase_04 AC 250 ms
26,988 KB
testcase_05 AC 126 ms
16,048 KB
testcase_06 AC 191 ms
22,584 KB
testcase_07 AC 213 ms
23,184 KB
testcase_08 AC 208 ms
27,068 KB
testcase_09 AC 97 ms
14,656 KB
testcase_10 AC 94 ms
14,640 KB
testcase_11 AC 151 ms
19,360 KB
testcase_12 AC 156 ms
19,388 KB
testcase_13 AC 113 ms
15,372 KB
testcase_14 AC 121 ms
18,200 KB
testcase_15 AC 242 ms
28,200 KB
testcase_16 AC 190 ms
23,052 KB
testcase_17 AC 87 ms
13,628 KB
testcase_18 AC 295 ms
30,984 KB
testcase_19 AC 297 ms
31,632 KB
testcase_20 AC 299 ms
32,164 KB
testcase_21 AC 297 ms
32,044 KB
testcase_22 AC 304 ms
33,516 KB
testcase_23 AC 297 ms
31,880 KB
testcase_24 AC 294 ms
31,308 KB
testcase_25 AC 293 ms
34,316 KB
testcase_26 AC 296 ms
32,736 KB
testcase_27 AC 294 ms
31,780 KB
testcase_28 AC 293 ms
31,316 KB
testcase_29 AC 293 ms
31,404 KB
testcase_30 AC 292 ms
30,844 KB
testcase_31 AC 293 ms
30,888 KB
testcase_32 AC 294 ms
31,260 KB
testcase_33 AC 275 ms
33,796 KB
testcase_34 AC 279 ms
31,804 KB
testcase_35 AC 273 ms
31,292 KB
testcase_36 AC 272 ms
31,568 KB
testcase_37 AC 272 ms
31,056 KB
testcase_38 AC 74 ms
19,340 KB
testcase_39 AC 132 ms
21,704 KB
testcase_40 AC 188 ms
31,424 KB
testcase_41 AC 2 ms
5,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define pb push_back
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define bug(x) cerr << (x) << '\n'
#define yn(x) cout << (x==1?"Yes\n":"No\n")
#define PI 3.14159265358979323
#define Ststone ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const ll max_n=2e5+20,max_int=2147483647,mod1=1e9+7,mod2=998244353;
const bool online = 0;
ll dx[8] = {1,0,0,-1,1,1,-1,-1};
ll dy[8] = {0,1,-1,0,1,-1,1,-1};
ll t,n,q,m,k,a,b,c,d,e,f,x,bit[max_n][3];
vector<ll> v1,v2,v3,v4;
vector<pii> v,era,out;
vector<pair<pii,pii>> ans;
char cc;
str s;

void update(ll index,ll dalta,ll num){
    while(index<=max_n){
        bit[index][num] += dalta;
        index += index&(-index);
    }
}

ll query(ll index,ll num){
    ll sum = 0;
    while(index){
        sum += bit[index][num];
        index -= index&(-index);
    }
    return sum;
}

void solve(){
    cin >> n;
    for(ll i=1;i<=n;i++){
        cin >> a >> b;
        v1.pb(a);
        v2.pb(b);
        v.pb({b,i});
        era.pb({a+b-1,i});
        update(i,a,0);
    }
    cin >> q;
    for(ll i=0;i<q;i++){
        cin >> a >> b >> c;
        ans.pb({{a,i},{b,c}});
    }
    sort(all(v));
    sort(all(era));
    sort(all(ans));
    ll l = 0,r = 0;
    for(ll i=0;i<q;i++){
        ll x = ans[i].F.F,y = ans[i].S.F,z = ans[i].S.S;
        while(l<n&&v[l].F<=x){
            update(v[l].S,v[l].F,1);
            update(v[l].S,1,2);
            l++;
        }
        while(r<n&&era[r].F<=x){
            //cout << r << " : " << era[r].S << '\n';
            update(era[r].S,-v1[era[r].S-1],0);
            update(era[r].S,-v2[era[r].S-1],1);
            update(era[r].S,-1,2);
            r++;
        }
        ll sum = query(z,0)-query(y-1,0) -( (x+1)*(query(z,2)-query(y-1,2)) - (query(z,1)-query(y-1,1)));
        out.pb({ans[i].F.S,sum});
        //cout << x << ' ' << query(100,0) << ' ' <<query(100,1) << '\n';
    }
    sort(all(out));
    for(ll i=0;i<q;i++){
        cout << out[i].S << '\n';
    }
    
}

int main(){
    Ststone;
    if(online){
        #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #else
        #endif
    }
    //cin >> t;
    t = 1;
    for(ll i=1;i<=t;i++){
        //cout << "Case #"<<i<<": ";
        solve();
    }
}


/*

*/
0