結果
| 問題 |
No.789 範囲の合計
|
| コンテスト | |
| ユーザー |
hornistyf
|
| 提出日時 | 2020-01-08 21:52:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,416 bytes |
| コンパイル時間 | 1,111 ms |
| コンパイル使用メモリ | 107,108 KB |
| 実行使用メモリ | 31,432 KB |
| 最終ジャッジ日時 | 2024-11-23 03:08:34 |
| 合計ジャッジ時間 | 6,843 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 RE * 7 |
ソースコード
//yuki789.cpp
//Wed Jan 8 20:11:42 2020
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;
ll nodenum,seg[400000];
void init(ll n){
nodenum = 1;
while (nodenum<n){
nodenum*=2;
}
fill(seg,seg+nodenum*2-1,0);
}
void add(ll index, ll x){
index += nodenum-1;
seg[index] += x;
while (index>0){
index = (index-1)/2;
seg[index] = seg[index*2+1]+seg[index*2+2];
}
}
ll query(ll a, ll b, ll k, ll l, ll r){
if (b<=l || r<=a){
return 0;
}
if (a<=l && r<=b){
return seg[k];
}else {
ll v1 = query(a,b,k*2+1,l,(l+r)/2);
ll v2 = query(a,b,k*2+2,(l+r)/2,r);
return v1+v2;
}
}
int main(){
ll n;
cin >> n;
ll q[n],x[n],y[n];
vector<ll> pos;
for (int i=0;i<n;i++){
cin >> q[i] >> x[i] >> y[i];
pos.push_back(x[i]);
pos.push_back(y[i]);
}
sort(pos.begin(),pos.end());
pos.erase(unique(pos.begin(),pos.end()),pos.end());
map<ll,ll> mpfor,mprev;
for (ll i=0;i<pos.size();i++){
mpfor[pos[i]] = i;
mprev[i] = pos[i];
}
init(pos.size());
ll ans = 0;
for (int i=0;i<n;i++){
if (q[i]){
ans += query(mpfor[x[i]],mpfor[y[i]]+1,0,0,nodenum);
}else{
add(mpfor[x[i]],y[i]);
}
}
cout << ans << endl;
// printf("%.4f\n",ans);
}
hornistyf