結果

問題 No.833 かっこいい電車
ユーザー 夜
提出日時 2021-03-02 20:10:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 1,039 ms
コンパイル使用メモリ 103,060 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-14 04:51:50
合計ジャッジ時間 5,743 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 127 ms
6,944 KB
testcase_11 AC 169 ms
7,808 KB
testcase_12 AC 54 ms
6,944 KB
testcase_13 AC 35 ms
6,940 KB
testcase_14 AC 139 ms
7,808 KB
testcase_15 AC 68 ms
6,944 KB
testcase_16 AC 57 ms
7,040 KB
testcase_17 AC 44 ms
6,944 KB
testcase_18 AC 153 ms
6,944 KB
testcase_19 AC 55 ms
6,940 KB
testcase_20 AC 16 ms
6,944 KB
testcase_21 AC 118 ms
6,940 KB
testcase_22 AC 96 ms
8,192 KB
testcase_23 AC 63 ms
6,940 KB
testcase_24 AC 94 ms
7,936 KB
testcase_25 AC 140 ms
6,940 KB
testcase_26 AC 66 ms
7,040 KB
testcase_27 AC 107 ms
6,940 KB
testcase_28 AC 72 ms
6,940 KB
testcase_29 AC 88 ms
6,944 KB
testcase_30 AC 99 ms
8,704 KB
testcase_31 AC 139 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long n, q;
vector<long long> BIT(100010);
void add(long long i, long long x) {
	while (i <= n) {
		BIT[i] += x;
		i += i & -i;
	}
}
long long csum(long long i) {
	long long count = 0;
	while (i > 0) {
		count += BIT[i];
		i -= i & -i;
	}
	return count;
}
long long sum(long long l, long long r) {
	return csum(r) - csum(l - 1);
}
set<long long> st;
int main(){
	cin >> n >> q;
	st.insert(0);
	for (int i = 1; i <= n; i++) {
		long long a;
		cin >> a;
		add(i, a);
		st.insert(i);
	}
	for (int i = 0; i < q; i++) {
		long long query, x;
		cin >> query >> x;
		if (query == 1) {
			st.erase(x);
		}
		else if (query == 2) {
			st.insert(x);
		}
		else if (query == 3) {
			add(x, 1);
		}
		else {
			auto itr = st.lower_bound(x);
			auto itr1 = itr--;
			cout << sum((*itr)+1, *itr1) << endl;
		}
	}
}
0