結果
問題 | No.1441 MErGe |
ユーザー | 沙耶花 |
提出日時 | 2021-02-08 15:53:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 341 ms / 1,000 ms |
コード長 | 5,321 bytes |
コンパイル時間 | 2,432 ms |
コンパイル使用メモリ | 199,156 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-04-20 10:33:03 |
合計ジャッジ時間 | 9,287 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,940 KB |
testcase_04 | AC | 4 ms
6,944 KB |
testcase_05 | AC | 8 ms
6,940 KB |
testcase_06 | AC | 8 ms
6,940 KB |
testcase_07 | AC | 7 ms
6,940 KB |
testcase_08 | AC | 69 ms
6,944 KB |
testcase_09 | AC | 68 ms
6,940 KB |
testcase_10 | AC | 107 ms
6,940 KB |
testcase_11 | AC | 100 ms
6,940 KB |
testcase_12 | AC | 108 ms
6,940 KB |
testcase_13 | AC | 253 ms
6,948 KB |
testcase_14 | AC | 261 ms
6,944 KB |
testcase_15 | AC | 271 ms
6,940 KB |
testcase_16 | AC | 241 ms
6,940 KB |
testcase_17 | AC | 238 ms
6,944 KB |
testcase_18 | AC | 214 ms
6,940 KB |
testcase_19 | AC | 251 ms
6,940 KB |
testcase_20 | AC | 195 ms
6,940 KB |
testcase_21 | AC | 176 ms
6,940 KB |
testcase_22 | AC | 242 ms
6,940 KB |
testcase_23 | AC | 325 ms
6,944 KB |
testcase_24 | AC | 338 ms
6,944 KB |
testcase_25 | AC | 328 ms
6,944 KB |
testcase_26 | AC | 333 ms
6,940 KB |
testcase_27 | AC | 341 ms
6,940 KB |
testcase_28 | AC | 167 ms
6,940 KB |
testcase_29 | AC | 168 ms
6,944 KB |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <cassert> #include <numeric> #include <type_traits> namespace atcoder { namespace internal { #ifndef _MSC_VER template <class T> using is_signed_int128 = typename std::conditional<std::is_same<T, __int128_t>::value || std::is_same<T, __int128>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int128 = typename std::conditional<std::is_same<T, __uint128_t>::value || std::is_same<T, unsigned __int128>::value, std::true_type, std::false_type>::type; template <class T> using make_unsigned_int128 = typename std::conditional<std::is_same<T, __int128_t>::value, __uint128_t, unsigned __int128>; template <class T> using is_integral = typename std::conditional<std::is_integral<T>::value || is_signed_int128<T>::value || is_unsigned_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using is_signed_int = typename std::conditional<(is_integral<T>::value && std::is_signed<T>::value) || is_signed_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int = typename std::conditional<(is_integral<T>::value && std::is_unsigned<T>::value) || is_unsigned_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using to_unsigned = typename std::conditional< is_signed_int128<T>::value, make_unsigned_int128<T>, typename std::conditional<std::is_signed<T>::value, std::make_unsigned<T>, std::common_type<T>>::type>::type; #else template <class T> using is_integral = typename std::is_integral<T>; template <class T> using is_signed_int = typename std::conditional<is_integral<T>::value && std::is_signed<T>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int = typename std::conditional<is_integral<T>::value && std::is_unsigned<T>::value, std::true_type, std::false_type>::type; template <class T> using to_unsigned = typename std::conditional<is_signed_int<T>::value, std::make_unsigned<T>, std::common_type<T>>::type; #endif template <class T> using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>; template <class T> using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>; template <class T> using to_unsigned_t = typename to_unsigned<T>::type; } // namespace internal } // namespace atcoder #include <cassert> #include <vector> namespace atcoder { // Reference: https://en.wikipedia.org/wiki/Fenwick_tree template <class T> struct fenwick_tree { using U = internal::to_unsigned_t<T>; public: fenwick_tree() : _n(0) {} fenwick_tree(int n) : _n(n), data(n) {} void add(int p, T x) { assert(0 <= p && p < _n); p++; while (p <= _n) { data[p - 1] += U(x); p += p & -p; } } T sum(int l, int r) { assert(0 <= l && l <= r && r <= _n); return sum(r) - sum(l); } private: int _n; std::vector<U> data; U sum(int r) { U s = 0; while (r > 0) { s += data[r - 1]; r -= r & -r; } return s; } }; } // namespace atcoder using namespace atcoder; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000000000000000 int N,Q; int Find(fenwick_tree<int> &F,int v){ int ok = -1,ng = N; while(ng-ok>1){ int mid = (ok+ng)/2; if(F.sum(0,mid)<v)ok = mid; else ng = mid; } return ok; } int main(){ scanf("%d %d",&N,&Q); vector<long long> S(N+1,0LL); rep(i,N){ scanf("%lld",&S[i+1]); S[i+1] += S[i]; } fenwick_tree<int> Fcnt(N),Fpos(N); rep(i,N){ Fcnt.add(i,1); Fpos.add(i,1); } rep(_,Q){ int T,l,r; scanf("%d %d %d",&T,&l,&r); if(T==1){ int x = Find(Fpos,l); while(r!=l){ int y = Find(Fpos,r); // cout<<Fpos.sum(0,N)<<','<<y<<endl; int t = Fcnt.sum(y,y+1); Fcnt.add(x,t); Fcnt.add(y,-t); Fpos.add(y,-1); r--; } } else{ //cout<<Fcnt.sum(0,Find(Fpos,r))<<endl; long long ans = S[Fcnt.sum(0,Find(Fpos,r)+1)] - S[Fcnt.sum(0,Find(Fpos,l-1)+1)]; printf("%lld\n",ans); } } return 0; }