結果

問題 No.833 かっこいい電車
ユーザー jupiro
提出日時 2020-02-08 08:26:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,895 bytes
コンパイル時間 1,080 ms
コンパイル使用メモリ 119,844 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-09-25 08:44:42
合計ジャッジ時間 3,282 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
class BIT {
private:
ll N;
vector<ll> node;
public:
BIT(ll M) {
node = vector<ll>(M + 1, 0);
N = M;
}
ll sum(ll i) {
ll s = 0;
while (i > 0) {
s += node[i];
i -= i & -i;
}
return s;
}
ll sum(ll i, ll j) {
ll l = sum(i - 1);
ll r = sum(j);
return r - l;
}
void add(ll i, ll x) {
while (i <= N) {
node[i] += x;
i += i & -i;
}
}
};
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
ll N, Q; scanf("%lld %lld", &N, &Q);
BIT bit(N + 5);
multiset<ll> ms; for (ll i = 1; i <= N + 1; i++) ms.insert(i);
for (ll i = 0; i < N; i++) {
ll x; scanf("%lld", &x);
bit.add(i + 1, x);
}
while (Q--) {
ll q, x; scanf("%lld %lld", &q, &x);
if (q == 1) {
auto itr = ms.find(x + 1);
if(itr != ms.end()) ms.erase(itr);
}
if (q == 2) {
if(ms.find(x+1) == ms.end()) ms.insert(x + 1);
}
if (q == 3) {
bit.add(x, 1);
}
if (q == 4) {
auto itr1 = ms.upper_bound(x);
auto itr2 = itr1;
itr2--;
printf("%lld\n", bit.sum(*itr2, *itr1 - 1));
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0