結果
問題 | No.789 範囲の合計 |
ユーザー |
![]() |
提出日時 | 2019-02-08 22:16:02 |
言語 | C++11 (gcc 8.5.0) |
結果 |
AC
|
実行時間 | 245 ms / 1,000 ms |
コード長 | 1,010 bytes |
コンパイル時間 | 681 ms |
使用メモリ | 17,112 KB |
最終ジャッジ日時 | 2023-02-01 16:44:58 |
合計ジャッジ時間 | 3,693 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,904 KB |
testcase_01 | AC | 1 ms
4,900 KB |
testcase_02 | AC | 227 ms
15,752 KB |
testcase_03 | AC | 70 ms
5,472 KB |
testcase_04 | AC | 211 ms
15,184 KB |
testcase_05 | AC | 165 ms
15,848 KB |
testcase_06 | AC | 180 ms
15,688 KB |
testcase_07 | AC | 61 ms
6,952 KB |
testcase_08 | AC | 126 ms
10,124 KB |
testcase_09 | AC | 116 ms
9,556 KB |
testcase_10 | AC | 245 ms
17,112 KB |
testcase_11 | AC | 184 ms
14,836 KB |
testcase_12 | AC | 184 ms
14,760 KB |
testcase_13 | AC | 2 ms
4,904 KB |
testcase_14 | AC | 2 ms
4,904 KB |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> using namespace std; typedef long long int ll; typedef pair<ll, int> P; int m; ll bit[300002]; ll sum(int i){ ll s=0; while(i>0){ s+=bit[i]; i-=(i&(-i)); } return s; } void add(int i, ll x){ while(i<=m){ bit[i]+=x; i+=(i&(-i)); } } int main() { int n; cin>>n; int t[100001]; ll x[100001], y[100001]; map<ll, int> mp; for(int i=0; i<n; i++){ cin>>t[i]>>x[i]>>y[i]; mp[x[i]]=0; if(t[i]==1) mp[y[i]]=0; } m=1; for(auto& p:mp){ p.second=m; m++; } for(int i=0; i<n; i++){ x[i]=mp[x[i]]; if(t[i]==1) y[i]=mp[y[i]]; } ll ans=0; for(int i=0; i<n; i++){ if(t[i]==0) add(x[i], y[i]); else ans+=(sum(y[i])-sum(x[i]-1)); } cout<<ans<<endl; return 0; }