結果

問題 No.833 かっこいい電車
ユーザー 沙耶花沙耶花
提出日時 2020-12-09 22:22:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 5,169 bytes
コンパイル時間 3,266 ms
コンパイル使用メモリ 210,556 KB
実行使用メモリ 8,860 KB
最終ジャッジ日時 2023-10-19 08:46:24
合計ジャッジ時間 5,161 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
6,136 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 72 ms
6,332 KB
testcase_11 AC 103 ms
7,804 KB
testcase_12 AC 30 ms
5,348 KB
testcase_13 AC 18 ms
4,488 KB
testcase_14 AC 86 ms
7,804 KB
testcase_15 AC 40 ms
6,016 KB
testcase_16 AC 34 ms
6,816 KB
testcase_17 AC 22 ms
4,348 KB
testcase_18 AC 89 ms
6,484 KB
testcase_19 AC 33 ms
6,484 KB
testcase_20 AC 9 ms
4,712 KB
testcase_21 AC 64 ms
5,076 KB
testcase_22 AC 58 ms
8,332 KB
testcase_23 AC 37 ms
6,596 KB
testcase_24 AC 57 ms
8,068 KB
testcase_25 AC 83 ms
6,100 KB
testcase_26 AC 39 ms
7,012 KB
testcase_27 AC 61 ms
6,308 KB
testcase_28 AC 39 ms
4,956 KB
testcase_29 AC 51 ms
5,792 KB
testcase_30 AC 79 ms
8,860 KB
testcase_31 AC 46 ms
6,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 Inf 10000000

int main(){
	
	int N,Q;
	cin>>N>>Q;
	
	map<int,int> mp;
	rep(i,N)mp[i] = i+1;
	
	fenwick_tree<long long> F(N);
	rep(i,N){
		int A;
		scanf("%d",&A);
		F.add(i,A);
	}
	
	rep(i,Q){
		int t,x;
		scanf("%d %d",&t,&x);
		x--;
		auto it = mp.upper_bound(x);
		it--;
		//cout<<(it->first)<<','<<(it->second)<<endl;
		if(t==1){
			if(it->second-1==x){
				int temp = it->first;
				it = mp.erase(it);
				int x = temp;
				int y = it->second;
				mp.erase(it);
				mp[x] = y;
			}
		}
		if(t==2){
			if(it->second-1!=x){
				int a = it->first;
				int b = x+1;
				int c = x+1;
				int d = it->second;
				mp.erase(it);
				mp[a] = b;
				mp[c] = d;
			}
		}
		if(t==3){
			F.add(x,1);
		}
		if(t==4){
			int l = it->first;
			int r = it->second;
			printf("%lld\n",F.sum(l,r));
		}
	}
	
	
    return 0;
}
0