結果

問題 No.833 かっこいい電車
ユーザー Yumeno Ukihashi
提出日時 2019-05-24 21:49:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,855 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 175,244 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-07-02 03:39:59
合計ジャッジ時間 4,484 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
using LL = long long;
using P = pair<int,int>;
int n,q;
LL tree[M];
int low(int x) { return x&-x; }
void add(int x,int v) {
for (int i=x; i<=n; i+=low(i))
tree[i] += v;
}
LL ask(int x) {
LL res = 0;
for (int i=x; i>0; i-=low(i))
res += tree[i];
return res;
}
LL ask(int x,int y) {
return ask(y) - ask(x-1);
}
int main()
{
set<P> s;
while (~scanf("%d %d", &n, &q)) {
s.clear();
MSET(tree, 0);
REP(i,1,n) {
int x;
scanf("%d", &x);
add(i, x);
}
REP(i,1,n) s.insert( make_pair(i,i) );
auto find_seg = [&](int x) {
auto it = s.upper_bound( make_pair(x+1, -1) );
if (it==s.begin()) return make_pair(-1, -1);
--it;
return *it;
};
REP(i,1,q) {
int x,y;
scanf("%d %d",&x,&y);
if (x==1) {
auto seg = find_seg(y);
auto seg2 = find_seg(y+1);
if (seg!=seg2) {
s.erase(seg);
s.erase(seg2);
s.insert(make_pair(seg.first, seg2.second));
}
}
if (x==2) {
auto seg = find_seg(y);
if (y+1 <= seg.second) {
s.erase(seg);
s.insert(make_pair(seg.first, y));
s.insert(make_pair(y+1, seg.second));
}
}
if (x==3) {
add(y, 1);
}
if (x==4) {
auto seg = find_seg(y);
printf("%lld\n", ask(seg.first, seg.second));
}
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0