結果
| 問題 |
No.833 かっこいい電車
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2019-05-24 23:04:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 160 ms / 2,000 ms |
| コード長 | 2,659 bytes |
| コンパイル時間 | 1,124 ms |
| コンパイル使用メモリ | 102,008 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 03:45:10 |
| 合計ジャッジ時間 | 3,889 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#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;
}
}
}
kotamanegi