結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
kyoprouno
|
| 提出日時 | 2020-02-29 13:16:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 396 ms / 2,000 ms |
| コード長 | 3,311 bytes |
| コンパイル時間 | 2,821 ms |
| コンパイル使用メモリ | 189,688 KB |
| 実行使用メモリ | 16,256 KB |
| 最終ジャッジ日時 | 2024-10-13 19:57:09 |
| 合計ジャッジ時間 | 7,176 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
for(T& x:vec) is >> x;
return is;
}
const ll INF=1e9+7;
struct LazySegmentTree{
private:
ll n;
vector<ll> node, lazy;
public:
LazySegmentTree(vector<ll> v){
ll sz=(ll)v.size();
n=1;
while(n<sz) n*=2;
node.resize(2*n-1);
lazy.resize(2*n-1,0);
rep(i,sz) node[i+n-1]=v[i];
for(ll i=n-2;i>=0;i--) node[i]=node[2*i+1]+node[2*i+2];
}
void eval(ll k,ll l,ll r){
if(lazy[k]!=0){
node[k]+=lazy[k];
if(r-l>1){
lazy[2*k+1]+=lazy[k]/2;
lazy[2*k+2]+=lazy[k]/2;
}
lazy[k]=0;
}
}
void add(ll a,ll b,ll x,ll k=0,ll l=0,ll r=-1){
if(r<0) r=n;
eval(k,l,r);
if(b<=l || r<=a) return;
if(a<=l && r<=b){
lazy[k]+=(r-l)*x;
eval(k,l,r);
}
else{
add(a,b,x,2*k+1,l,(l+r)/2);
add(a,b,x,2*k+2,(l+r)/2,r);
node[k]=node[2*k+1]+node[2*k+2];
}
}
ll getsum(ll a,ll b,ll k=0,ll l=0,ll r=-1){
if(r<0) r=n;
if(b<=l || r<=a) return 0;
eval(k,l,r);
if(a<=l && r<=b) return node[k];
ll vl=getsum(a,b,2*k+1,l,(l+r)/2);
ll vr=getsum(a,b,2*k+2,(l+r)/2,r);
return vl+vr;
}
};
int main()
{
ll n,q;
cin >> n >> q;
vector<ll> a(n);
rep(i,n) cin >> a[i];
vector<ll> b(n);
LazySegmentTree seg(b);
while(q--){
char c;
ll x,y;
cin >> c >> x >> y;
if(c=='A'){
x--;
b[x]+=seg.getsum(x,x+1)*(-y);
a[x]+=y;
}
else{
x--;
y--;
seg.add(x,y+1,1);
}
}
rep(i,n){
b[i]+=seg.getsum(i,i+1)*a[i];
}
rep(i,n){
if(i) cout << " ";
cout << b[i];
}
cout << endl;
return 0;
}
kyoprouno