結果

問題 No.833 かっこいい電車
ユーザー 👑 jupirojupiro
提出日時 2020-02-08 08:19:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,849 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 119,444 KB
実行使用メモリ 8,888 KB
最終ジャッジ日時 2023-10-26 00:44:57
合計ジャッジ時間 5,935 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
6,168 KB
testcase_01 RE -
testcase_02 WA -
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 9 ms
4,744 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 64 ms
8,888 KB
testcase_31 AC 43 ms
6,168 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.upper_bound(x);
			ms.erase(itr);
		}
		if (q == 2) {
			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