結果

問題 No.789 範囲の合計
ユーザー Ngọc Hưng NguyễnNgọc Hưng Nguyễn
提出日時 2022-07-14 06:41:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 369 ms / 1,000 ms
コード長 4,595 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 172,216 KB
実行使用メモリ 24,796 KB
最終ジャッジ日時 2023-09-07 18:51:05
合計ジャッジ時間 5,660 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 346 ms
22,208 KB
testcase_03 AC 58 ms
4,376 KB
testcase_04 AC 369 ms
23,064 KB
testcase_05 AC 313 ms
22,284 KB
testcase_06 AC 309 ms
22,520 KB
testcase_07 AC 77 ms
4,376 KB
testcase_08 AC 277 ms
24,272 KB
testcase_09 AC 260 ms
22,892 KB
testcase_10 AC 276 ms
14,288 KB
testcase_11 AC 360 ms
24,796 KB
testcase_12 AC 339 ms
24,664 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// -------------------------Solution by Stormgamming------------------------- //
/* Author : Nguyen Ngoc Hung, Ngo Gia Tu high school */

/*
Tips:
    1.int? long long?
    2.don't submit wrong answer
    3.figure out logic first, then start writing please
    4.know about the range
    5.check if you have to input t or not
    6.modulo of negative numbers is not a%b, it is a%b + abs(b)

┏━━┓┏━━┓┏━━┓┏━━┓
┗━┓┃┃┏┓┃┗━┓┃┗━┓┃
┏━┛┃┃┃┃┃┏━┛┃┏━┛┃
┃┗━┓┃┗┛┃┃┗━┓┃┗━┓
┗━━┛┗━━┛┗━━┛┗━━┛
*/
#include <bits/stdc++.h>

using namespace std;

/***PRAGMA***/
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma GCC target ("sse4")

/***TEMPLATE***/
#define DEBUG(X) {auto _X=(X); cerr << "L" << __LINE__ << ": " << #X << " = " << (_X) << endl;}
#define __Storgamming__ signed main()
#define count_bit(mask) __builtin_popcountll(mask)
#define repdis(i,be,en,j) for(int i = (be); i<=(en); i+=j)
#define rep(i,be,en) for(int i = (be); i<=(en); i++)
#define repd(i,be,en) for(int i = (be); i>=(en); i--)
#define trav(a,x) for(auto& a:x)
#define on(i,m) (m|=(1LL<<i))
#define off(i,m) (m&=~(1LL<<i))
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define inf 0x3f3f3f3f
#define mp make_pair
#define pii pair<int,int>
#define ull unsigned long long
#define ll long long
#define ld long double
#define int long long
#define fi first
#define se second
#define endl "\n"
#define bit(i,j) ((i>>j)&1ll)
#define mask(i) (1ll<<i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x).size()
#define uni(a) ((a).erase(unique(all(a)),(a).end()))
#define reset(x,val) memset((x),(val),sizeof(x))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

/***DEBUG CODE***/
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(ld x) {cerr << x;}
void __print(ull x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/***Common Functions***/
template<class T> bool ckmin(T& a, const T& b){return a>b?a=b,1:0;}
template<class T> bool ckmax(T& a, const T& b){return a<b?a=b,1:0;}
template<typename num_t>void add_mod(num_t& a, const long long& b, const int& m){a=(a+b)%m;if(a>=m)a-=m;if(a<0)a+=m;}
template<typename num_t>num_t gcd(num_t lhs, num_t rhs) {return !lhs?rhs:gcd(rhs%lhs,lhs);}
template<typename num_t>num_t pw(num_t n, num_t k, const num_t& mod){if(k==-1)k=mod-2;num_t res=1;for(; k>0;k>>=1){if(k&1)res=1ll*res*n%mod;n=1ll*n*n%mod;}return res%mod;}

const int N = (int)1e6+1;
const int SIZE = (int)1e6+10;
const int maxn = (int)1e9+6;
const int MOD = (int)1e9+7;
const int oo = (int)1e18+7;
const int base = (int)311;
const ld PI = 4*atan((ld)1);

/***End of Template***/

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
unordered_map<int,int> f;

void add(int id, int val){
  for(++id; id<=maxn; id+=id&-id){
    f[id] += val;
  }
}

int s(int id){
  int res = 0;
  for(++id; id>0; id-=id&-id){
    if(f.count(id)>0){
      res += f[id];
    }
  }
  return res;
}

int sum(int l, int r){
  return s(r)-s(l-1);
}

void solve(){
  int n,l,r,type,res = 0;
  cin >> n;
  while(n--){
    cin >> type >> l >> r;
    if(type==0){
      add(l,r);
    }else{
      res += sum(l,r);
    }
  }
  cout << res;
}

__Storgamming__{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin.exceptions(ios::badbit | ios::failbit);

   // freopen("A.inp", "r", stdin);
   // freopen("A.out", "w", stdout);

    int test = 1;

    while(test--){
        solve();
    }
    return 0;
}

/**  
*      ʕ•ᴥ•ʔ
*  [storgamming]
*       U U
*/
0