結果
| 問題 |
No.789 範囲の合計
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-15 18:11:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 489 ms / 1,000 ms |
| コード長 | 2,853 bytes |
| コンパイル時間 | 1,740 ms |
| コンパイル使用メモリ | 132,212 KB |
| 最終ジャッジ日時 | 2025-01-30 07:13:56 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
//#include <atcoder/all>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
const ll inf=1e18;
using graph = vector<vector<int> > ;
using P= pair<ll,ll>;
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vp=vector<P>;
using vpp=vector<vp>;
//string T="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//string S="abcdefghijklmnopqrstuvwxyz";
//g++ main.cpp -std=c++14 -I .
//cout <<setprecision(20);
//cout << fixed << setprecision(10);
map<int,ll>d;
void comp(vector<int>&a){
set<int>s(a.begin(),a.end());
int cnt=0;
for(auto y:s)d[y]=cnt++;
for(auto&y:a)y=d[y];
}
using np=pair<int,P>;
const ll seg_size=(1ll<<20);
ll seg_take(int l,int r,vector<int> &seg){
l+=seg.size()/2;
r+=seg.size()/2;
ll res=0;
while(l<r){
if(l%2==1){
res+=seg[l];
l++;
}
l/=2;
if(r%2==1){
res+=seg[r-1];
r--;
}
r/=2;
}
return res;
}
void seg_set(int ind,ll v,vector<int> &seg){
ind+=seg.size()/2;
seg[ind]+=v;
while(ind>0){
ind/=2;
seg[ind]=seg[2*ind]+seg[ind*2+1];
}
}
int main(){
int q; cin >> q;
int n=2*q;
int n2=1;
while(n2<=n)n2*=2;
vector<np> Q;
vi a;
rep(i,q){
int t; cin >> t;
if(t==0){
int x,y; cin >> x >> y;
Q.push_back(np(0,P(x,y)));
a.push_back(x);
}
else {
int l,r; cin >> l >> r;
Q.push_back(np(1,P(l,r)));
a.push_back(l);
a.push_back(r);
}
}
comp(a);
rep(i,q){
int t=Q[i].first;
if(t==0){
Q[i].second.first=d[Q[i].second.first];
}
else {
Q[i].second.first=d[Q[i].second.first];
Q[i].second.second=d[Q[i].second.second];
}
}
vi seg(n2*2);
ll ans=0;
rep(i,q){
int t=Q[i].first;
if(t==0){
int x=Q[i].second.first,y=Q[i].second.second;
seg_set(x,y,seg);
}
else {
int l=Q[i].second.first,r=Q[i].second.second;
ll v=seg_take(l,r+1,seg);
ans+=v;
}
}
cout << ans << endl;
}