結果
問題 | No.876 Range Compress Query |
ユーザー |
![]() |
提出日時 | 2019-09-06 21:34:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 1,237 bytes |
コンパイル時間 | 868 ms |
コンパイル使用メモリ | 72,064 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 17:01:41 |
合計ジャッジ時間 | 2,502 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#include <iostream> #include <vector> using namespace std; #pragma warning (disable: 4996) class BIT { public: vector<long long> bit; int size_; void init(int sz) { size_ = sz + 2; bit.resize(size_ + 2, 0); } void add(int pos, long long x) { pos++; while (pos <= size_) { bit[pos] += x; pos += (pos&-pos); } } long long sum(int pos) { long long s = 0; pos++; while (pos >= 1) { s += bit[pos]; pos -= (pos&-pos); } return s; } }; long long N, Q, A[1 << 17], B[1 << 17]; BIT Z; int main() { scanf("%lld%lld", &N, &Q); Z.init(N + 2); for (int i = 1; i <= N; i++) scanf("%lld", &A[i]); for (int i = 1; i <= N - 1; i++) B[i] = A[i + 1] - A[i]; for (int i = 1; i <= N - 1; i++) { if (B[i] != 0) Z.add(i, 1); } for (int i = 1; i <= Q; i++) { int ty, l, r, x; scanf("%d", &ty); if (ty == 1) { scanf("%d%d%d", &l, &r, &x); if (l >= 2) { if (B[l - 1] != 0) Z.add(l - 1, -1); B[l - 1] += x; if (B[l - 1] != 0) Z.add(l - 1, 1); } if (r <= N - 1) { if (B[r] != 0) Z.add(r, -1); B[r] -= x; if (B[r] != 0) Z.add(r, 1); } } if (ty == 2) { scanf("%d%d", &l, &r); long long v = Z.sum(r - 1) - Z.sum(l - 1); printf("%lld\n", v + 1); } } return 0; }