結果
| 問題 | No.789 範囲の合計 |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-07-24 22:42:40 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 1,000 ms |
| + 825µs | |
| コード長 | 751 bytes |
| 記録 | |
| コンパイル時間 | 1,080 ms |
| コンパイル使用メモリ | 179,364 KB |
| 実行使用メモリ | 8,192 KB |
| 最終ジャッジ日時 | 2026-07-24 22:42:43 |
| 合計ジャッジ時間 | 3,001 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int M=600010;
int q,m,t[M];
long long x[M],y[M],c[M],a[M],s;
void u(int i,long long v){for(;i<=m;i+=i&-i)a[i]+=v;}
long long qy(int i){long long r=0;for(;i;i-=i&-i)r+=a[i];return r;}
int main(){
scanf("%d",&q);
for(int i=0;i<q;++i){
scanf("%d%lld%lld",&t[i],&x[i],&y[i]);
if(t[i])c[m++]=x[i],c[m++]=y[i];
else c[m++]=x[i];
}
sort(c,c+m);
m=unique(c,c+m)-c;
for(int i=0;i<q;++i){
if(t[i]){
int l=lower_bound(c,c+m,x[i])-c;
int r=upper_bound(c,c+m,y[i])-c-1;
if(l<=r)s+=qy(r+1)-qy(l);
}else{
int p=lower_bound(c,c+m,x[i])-c;
u(p+1,y[i]);
}
}
printf("%lld",s);
}
vjudge1