結果

問題 No.789 範囲の合計
ユーザー akuaakua
提出日時 2022-07-15 18:11:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 443 ms / 1,000 ms
コード長 2,853 bytes
コンパイル時間 1,460 ms
コンパイル使用メモリ 136,716 KB
実行使用メモリ 24,376 KB
最終ジャッジ日時 2023-09-09 20:35:36
合計ジャッジ時間 5,438 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 386 ms
21,964 KB
testcase_03 AC 86 ms
9,028 KB
testcase_04 AC 361 ms
23,268 KB
testcase_05 AC 265 ms
22,516 KB
testcase_06 AC 291 ms
21,912 KB
testcase_07 AC 74 ms
9,304 KB
testcase_08 AC 192 ms
15,344 KB
testcase_09 AC 187 ms
14,572 KB
testcase_10 AC 443 ms
24,376 KB
testcase_11 AC 306 ms
21,720 KB
testcase_12 AC 306 ms
21,512 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#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;

  
   
}   
0