結果
問題 | No.1000 Point Add and Array Add |
ユーザー | mtsd |
提出日時 | 2020-02-28 21:52:06 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 568 ms / 2,000 ms |
コード長 | 3,404 bytes |
コンパイル時間 | 1,315 ms |
コンパイル使用メモリ | 127,252 KB |
実行使用メモリ | 23,248 KB |
最終ジャッジ日時 | 2023-08-03 20:05:59 |
合計ジャッジ時間 | 6,901 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,384 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 4 ms
4,376 KB |
testcase_13 | AC | 3 ms
4,380 KB |
testcase_14 | AC | 5 ms
4,384 KB |
testcase_15 | AC | 4 ms
4,384 KB |
testcase_16 | AC | 329 ms
18,428 KB |
testcase_17 | AC | 291 ms
16,588 KB |
testcase_18 | AC | 481 ms
22,660 KB |
testcase_19 | AC | 480 ms
22,376 KB |
testcase_20 | AC | 256 ms
22,480 KB |
testcase_21 | AC | 568 ms
22,648 KB |
testcase_22 | AC | 318 ms
22,192 KB |
testcase_23 | AC | 546 ms
23,248 KB |
ソースコード
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <iomanip> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #include <cstdint> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } template<class T> inline bool chmax(T &a, T b){ if(a<b){ a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b){ if(a>b){ a = b; return true; } return false; } template<typename T> class segtree { private: int n,sz,h; vector<T> node, lazy; void eval(int k) { if(lazy[k]){ node[k] += lazy[k]; if(k < n) { lazy[k*2] += lazy[k] / 2, lazy[k*2+1] += lazy[k] / 2; } lazy[k] = 0; } } public: segtree(const vector<T>& v) : n(1), sz((int)v.size()), h(0) { while(n < sz) n *= 2, h++; node.resize(2*n, 0), lazy.resize(2*n, 0); for(int i = 0; i < sz; i++) node[i+n] = v[i]; for(int i = n-1; i >= 1; i--) node[i] = node[2*i] + node[2*i+1]; } void range(int a, int b, T x, int k=1, int l=0, int r=-1){ if(r < 0) r = n; eval(k); if(b <= l || r <= a){ return; } if(a <= l && r <= b){ lazy[k] += (r-l)*x; eval(k); }else{ range(a, b, x, 2*k, l, (l+r)/2); range(a, b, x, 2*k+1, (l+r)/2, r); node[k] = node[2*k] + node[2*k+1]; } } T query(int a, int b) { a += n, b += n - 1; for(int i = h; i > 0; i--) eval(a >> i), eval(b >> i); b++; T res1 = 0, res2 = 0; while(a < b) { if(a & 1) eval(a), res1 += node[a++]; if(b & 1) eval(--b), res2 += node[b]; a >>= 1, b >>= 1; } return res1 + res2; } void print(){for(int i = 0; i < sz; i++) cout<<query(i,i+1)<< " ";cout<<endl;} }; int main(){ ll n,q; cin >> n >> q; vector<ll>a(n); segtree<ll> sg(a); vector<ll>res(n); vector<ll>p(n); rep(i,n){ cin >> p[i]; } vector<pair<int,pair<ll,ll> > > Q; rep(i,q){ char c; ll a,b; cin >> c >> a >> b; if(c=='A'){ a--; Q.push_back(MP(0,MP(a,b))); }else{ a--;b--; Q.push_back(MP(1,MP(a,b))); sg.range(a,b+1,1); } } rep(i,n){ res[i] += sg.query(i,i+1)*p[i]; } rep(i,q){ if(Q[i].first==0){ res[Q[i].second.first] += sg.query(Q[i].second.first,Q[i].second.first+1)*Q[i].second.second; }else{ sg.range(Q[i].second.first,Q[i].second.second+1,-1); } } rep(i,n){ cout << res[i] << " "; } cout << endl; return 0; }