結果
| 問題 |
No.833 かっこいい電車
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-06-27 23:41:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 90 ms / 2,000 ms |
| コード長 | 2,483 bytes |
| コンパイル時間 | 717 ms |
| コンパイル使用メモリ | 88,392 KB |
| 実行使用メモリ | 5,504 KB |
| 最終ジャッジ日時 | 2024-07-06 04:43:08 |
| 合計ジャッジ時間 | 3,668 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
template <typename T>
struct bit{
int n;
vector<T> data;
bit(int n_){
n = 1;
while(n < n_) n *= 2;
data = vector<T>(n+1);
for(int i = 0; i <= n; i++) data[i] = 0;
}
T sum(int i){
T ret = 0;
while(i > 0){
ret += data[i];
i -= i&-i;
}
return ret;
}
void add(int i, T x){
while(i <= n){
data[i] += x;
i += i&-i;
}
}
};
int N, Q;
ll A[100000];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> N >> Q;
bit<ll> bt_sum(N);
bit<int> bt_union(N);
for(int i = 0; i < N; i++) {
cin >> A[i];
bt_sum.add(i+1, A[i]);
}
for(int i = 2; i <= N; i++) bt_union.add(i, 1);
for(int i = 0; i < Q; i++){
int c, x; cin >> c >> x;
if(c == 1){
if(bt_union.sum(x) != bt_union.sum(x+1)){
bt_union.add(x+1, -1);
}
}
if(c == 2){
if(bt_union.sum(x) == bt_union.sum(x+1)){
bt_union.add(x+1, 1);
}
}
if(c == 3){
bt_sum.add(x, 1);
}
if(c == 4){
// 左端
int l_idx;
{
int l = 0, r = x;
while(r-l > 1){
int c = (l+r)/2;
if(bt_union.sum(c) != bt_union.sum(x)) l = c;
else r = c;
}
l_idx = r;
}
// 右端
int r_idx;
{
int l = x, r = N;
if(bt_union.sum(r) == bt_union.sum(x)) r_idx = r;
else{
while(r-l > 1){
int c = (l+r)/2;
if(bt_union.sum(c) != bt_union.sum(x)) r = c;
else l = c;
}
r_idx = l;
}
}
// cout << "ans" << endl;
// cout << l_idx << ' ' << r_idx << endl;
cout << bt_sum.sum(r_idx)-bt_sum.sum(l_idx-1) << endl;
}
// cout << "union" << endl;
// for(int i = 1; i < N; i++) cout << bt_union.sum(i) << ' ';
// cout << endl;
}
}
milanis48663220