結果

問題 No.833 かっこいい電車
ユーザー kotamanegikotamanegi
提出日時 2019-05-24 23:04:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 2,659 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 99,132 KB
実行使用メモリ 4,744 KB
最終ジャッジ日時 2023-09-14 20:55:03
合計ジャッジ時間 3,987 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 82 ms
4,380 KB
testcase_11 AC 102 ms
4,720 KB
testcase_12 AC 34 ms
4,380 KB
testcase_13 AC 27 ms
4,380 KB
testcase_14 AC 84 ms
4,708 KB
testcase_15 AC 44 ms
4,376 KB
testcase_16 AC 33 ms
4,428 KB
testcase_17 AC 37 ms
4,376 KB
testcase_18 AC 99 ms
4,456 KB
testcase_19 AC 33 ms
4,376 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 87 ms
4,380 KB
testcase_22 AC 54 ms
4,744 KB
testcase_23 AC 37 ms
4,432 KB
testcase_24 AC 55 ms
4,644 KB
testcase_25 AC 94 ms
4,380 KB
testcase_26 AC 40 ms
4,376 KB
testcase_27 AC 65 ms
4,380 KB
testcase_28 AC 51 ms
4,376 KB
testcase_29 AC 59 ms
4,376 KB
testcase_30 AC 60 ms
4,380 KB
testcase_31 AC 136 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD  998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
long long inv(long long now) {
	long long ans = 1;
	long long te = MAX_MOD - 2LL;
	while (te != 0) {
		if (te % 2 == 1) {
			ans *= now;
			ans %= MAX_MOD;
		}
		te /= 2;
		now *= now;
		now %= MAX_MOD;
	}
	return ans;
}
#define SIZE 100
long long ok_compact[100000 / SIZE * 2] = {};
long long cost[200000];
long long is_connected[200000];
int main(){
#define int long long
	int n, query;
	cin >> n >> query;
	REP(i, n) {
		cin >> cost[i];
	}
	REP(i, query) {
		int a;
		int b;
		cin >> a >> b;
		b--;
		if (a == 1) {
			if (is_connected[b] == 0) {
				is_connected[b] = 1;
				int ok = 1;
				for (int q = b / SIZE * SIZE; q < (b / SIZE + 1) * SIZE && q < n; ++q) {
					ok &= is_connected[q];
					ok_compact[b / SIZE] += cost[q];
				}
				ok_compact[b / SIZE] *= ok;
			}
		}
		else if (a == 2) {
			if (is_connected[b] == 1) {
				is_connected[b] = 0;
				if (ok_compact[b / SIZE] != 0) {
					ok_compact[b / SIZE] = 0;
				}
			}
		}
		else if (a == 3) {
			cost[b]++;
			if (ok_compact[b / SIZE] != 0) {
				ok_compact[b / SIZE]++;
			}
		}
		else {
			//output;
			long long now_ans = 0;
			long long now_itr_back = b;//back <= 
			long long now_itr_front = b;
			if (ok_compact[b / SIZE] != 0) {
				now_ans += ok_compact[b / SIZE];
				now_itr_back = b/SIZE * SIZE;
				for (int q = b / SIZE - 1; q >= 0; --q) {
					if (ok_compact[q] == 0) break;
					now_ans += ok_compact[q];
					now_itr_back = q * SIZE;
				}
				now_itr_front = (b / SIZE + 1) * SIZE;
				for (int q = b / SIZE + 1;; ++q) {
					if (ok_compact[q] == 0) break;
					now_ans += ok_compact[q];
					now_itr_front = (q+1) * SIZE;
				}
			}
			for (int q = now_itr_back - 1; q >= 0; --q) {
				if (is_connected[q] == 0) break;
				now_ans += cost[q];
			}
			for (int q = now_itr_front;; ++q) {
				now_ans += cost[q];
				if (is_connected[q] == 0) break;
			}
			cout << now_ans << endl;
		}
	}
}
0