結果

問題 No.833 かっこいい電車
ユーザー 👑 jupirojupiro
提出日時 2020-02-08 08:26:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,895 bytes
コンパイル時間 1,145 ms
コンパイル使用メモリ 119,920 KB
実行使用メモリ 8,916 KB
最終ジャッジ日時 2023-10-26 00:45:02
合計ジャッジ時間 3,496 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
6,184 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 1 ms
4,368 KB
testcase_10 AC 59 ms
6,380 KB
testcase_11 AC 78 ms
7,860 KB
testcase_12 AC 25 ms
5,396 KB
testcase_13 AC 15 ms
4,536 KB
testcase_14 AC 70 ms
7,860 KB
testcase_15 AC 35 ms
6,064 KB
testcase_16 AC 32 ms
6,864 KB
testcase_17 AC 17 ms
4,368 KB
testcase_18 AC 68 ms
6,540 KB
testcase_19 AC 30 ms
6,540 KB
testcase_20 AC 9 ms
4,760 KB
testcase_21 AC 49 ms
5,124 KB
testcase_22 AC 51 ms
8,388 KB
testcase_23 AC 34 ms
6,644 KB
testcase_24 AC 50 ms
8,124 KB
testcase_25 AC 64 ms
6,148 KB
testcase_26 AC 37 ms
7,068 KB
testcase_27 AC 50 ms
6,356 KB
testcase_28 AC 31 ms
5,004 KB
testcase_29 AC 41 ms
5,840 KB
testcase_30 AC 66 ms
8,916 KB
testcase_31 AC 43 ms
6,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

class BIT {
private:
	ll N;
	vector<ll> node;
public:
	BIT(ll M) {
		node = vector<ll>(M + 1, 0);
		N = M;
	}

	ll sum(ll i) {
		ll s = 0;
		while (i > 0) {
			s += node[i];
			i -= i & -i;
		}
		return s;
	}

	ll sum(ll i, ll j) {
		ll l = sum(i - 1);
		ll r = sum(j);
		return r - l;
	}

	void add(ll i, ll x) {
		while (i <= N) {
			node[i] += x;
			i += i & -i;
		}
	}
};

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll N, Q; scanf("%lld %lld", &N, &Q);
	BIT bit(N + 5);
	multiset<ll> ms; for (ll i = 1; i <= N + 1; i++) ms.insert(i);
	for (ll i = 0; i < N; i++) {
		ll x; scanf("%lld", &x);
		bit.add(i + 1, x);
	}
	while (Q--) {
		ll q, x; scanf("%lld %lld", &q, &x);
		if (q == 1) {
			auto itr = ms.find(x + 1);
			if(itr != ms.end()) ms.erase(itr);
		}
		if (q == 2) {
			if(ms.find(x+1) == ms.end()) ms.insert(x + 1);
		}
		if (q == 3) {
			bit.add(x, 1);
		}
		if (q == 4) {
			auto itr1 = ms.upper_bound(x);
			auto itr2 = itr1;
			itr2--;
			printf("%lld\n", bit.sum(*itr2, *itr1 - 1));
			
		}
	}
	return 0;
}
0