結果

問題 No.789 範囲の合計
コンテスト
ユーザー vjudge1
提出日時 2026-07-24 22:34:16
言語 C++11
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 44 ms / 1,000 ms
+ 929µs
コード長 787 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 975 ms
コンパイル使用メモリ 179,256 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2026-07-24 22:34:20
合計ジャッジ時間 3,339 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
const int M=600010;
int q,m,c[M],o[M][3];
long long a[M],s;
void u(int i,long long x){for(;i<=m;i+=i&-i)a[i]+=x;}
long long qy(int i){long long t=0;for(;i;i-=i&-i)t+=a[i];return t;}
int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>q;
    for(int i=0;i<q;++i){
        cin>>o[i][0]>>o[i][1]>>o[i][2];
        if(o[i][0])c[m++]=o[i][1],c[m++]=o[i][2];
        else c[m++]=o[i][1];
    }
    sort(c,c+m);
    m=unique(c,c+m)-c;
    for(int i=0;i<q;++i){
        if(o[i][0]){
            int l=lower_bound(c,c+m,o[i][1])-c;
            int r=upper_bound(c,c+m,o[i][2])-c-1;
            if(l<=r)s+=qy(r+1)-qy(l);
        }else{
            int p=lower_bound(c,c+m,o[i][1])-c;
            u(p+1,o[i][2]);
        }
    }
    cout<<s;
}
0