結果

問題 No.833 かっこいい電車
ユーザー aya_seaya_se
提出日時 2019-05-25 01:38:25
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,310 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 81,112 KB
実行使用メモリ 14,672 KB
最終ジャッジ日時 2023-09-14 21:02:01
合計ジャッジ時間 7,505 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
using namespace std;
typedef long long ll;
//定義場所//
int i, j, k, l, m, n;
int N, Q;
vector<ll> A;
set<int> border;//i両目の左隣に仕切り
vector<ll> Ans;
////////////

int main()
{
	cin >> N >> Q;
	for (i = 0; i < N; i++) {
		ll a;
		cin >> a;
		A.push_back(a);
		border.insert(i);
	}
	for (i = 0; i < Q; i++) {
		int q;
		int x;
		cin >> q >> x;
		if (q == 1 && border.count(x-1)==1) {
			border.erase(x-1);
		}
		else if (q == 2 && border.count(x-1) == 0) {
			border.insert(x-1);
		}
		else if (q == 3) {
			A[x - 1]++;
		}
		else if (q == 4){
			int right = *lower_bound(border.begin(), border.end(), x-1);
			int left = x - 2;
			while (left >= 0) {
				if (border.count(left) == 1) {
					break;
				}
				else {
					left--;
				}
			}
			ll ans = 0;
			for (j = left + 1; j <= right; j++) {
				ans += A[j];
			}
			Ans.push_back(ans);
		}
	}
	for (i = 0; i < Ans.size(); i++) {
		cout << Ans[i] << endl;
	}
}
0