Daffodil International University
Problem Link
//Please follow from main function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
/// Typedef | |
typedef long long ll; | |
typedef unsigned long ul; | |
typedef unsigned long long ull; | |
typedef vector<int> vi; | |
typedef vector<vi> vvi; | |
typedef vector<ll> vll; | |
typedef pair<int,int> pii; | |
typedef pair<ll,ll> pll; | |
typedef vector< pii > vii; | |
#define pb push_back | |
#define ppb pop_back | |
#define MP make_pair | |
#define ff first | |
#define ss second | |
#define sf scanf | |
#define pf printf | |
#define SQR(x) ((x)*(x)) | |
#define loop(i, y) for(int i=0; i<int(y); i++) | |
#define FOR(i, x, y) for(int i=int(x); i<=int(y); i++) | |
#define ROF(i, x, y) for(int i=int(x); i>=int(y); i--) | |
#define ALL(c) c.begin(), c.end() | |
#define SZ(c) int(c.size()) | |
#define CLR(x, y) memset(x, y, sizeof(x)) | |
#define READ(f) freopen(f, "r", stdin) | |
#define WRITE(f) freopen(f, "w", stdout) | |
#define FastIO ios_base::sync_with_stdio(false) | |
#define tr(it, container) for(auto it = container.begin(); it != container.end(); it++) | |
#define sci(x) scanf("%d", &x) | |
#define scii(x, y) scanf("%d %d", &x, &y) | |
#define sciii(x, y, z) scanf("%d %d %d", &x, &y, &z) | |
#define scl(x) scanf("%lld", &x) | |
#define scll(x, y) scanf("%lld %lld", &x, &y) | |
#define sclll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z) | |
#define bitCheck(N,in) ((bool)(N&(1<<(in)))) | |
#define bitOff(N,in) (N&(~(1LL<<(in)))) | |
#define bitOn(N,in) (N|(1LL<<(in))) | |
#define bitFlip(a,k) (a^(1LL<<(k))) | |
#define unq(v) sort(all(v)), (v).erase(unique(all(v)),v.end()) | |
#define common(a,b) sort(all(a)), sort(all(b)), a.erase(set_intersection(all(a),all(b),a.begin()),a.end()) | |
#define uncommon(a,b) sort(all(a)), sort(all(b)), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end()) | |
#define dbg(x) cout<<#x<<" = "<<x<<endl; | |
template <class T> inline T bigMod(T p,T e,T M){ ll ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;} | |
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);} | |
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);} | |
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;} | |
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();} | |
const int dr[] = { 0, 1, 0, -1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1}; | |
const int dc[] = { 1, 0, -1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2}; | |
#define for1(a,b) for(ll i=a; i<b; i++) | |
#define rev(v) reverse(v.begin(),v.end()) | |
#define srt(v) sort(v.begin(),v.end()) | |
#define grtsrt(v) sort(v.begin(),v.end(),greater<ll>()) | |
/// Constants | |
#define mx 200001 | |
#define MOD 1000000009 | |
#define base 1000000007 | |
#define eps 1e-9 | |
#define INF 1llu<<61 // 2,305,843,009,213,693,952 | |
#define inf 1<<29 // 536,870,912 | |
#define PI acos(-1.0) // 3.1415926535897932 | |
ll tree[mx*4], arr[mx]; | |
void init(ll node, ll b, ll e){ | |
if(b==e){ | |
tree[node]=arr[b]; | |
return; | |
} | |
ll lft=node<<1; | |
ll rft=lft|1; | |
ll mid=(b+e)>>1; | |
init(lft, b, mid); | |
init(rft, mid+1, e); | |
tree[node]=tree[lft]+tree[rft]; | |
} | |
void update(ll node, ll b, ll e, ll i, ll v){ | |
if(i<b || i>e)return; | |
if(i==b && i==e){ | |
tree[node]=v; | |
return; | |
} | |
ll lft=node<<1; | |
ll rft=lft|1; | |
ll mid=(b+e)>>1; | |
update(lft,b,mid,i,v); | |
update(rft,mid+1,e,i,v); | |
tree[node]=tree[lft]+tree[rft]; | |
} | |
ll query(ll node, ll b, ll e, ll i, ll j){ | |
if(i>e || b>j )return 0; | |
if(b>=i && e<=j){ | |
return tree[node]; | |
} | |
ll lft=node<<1; | |
ll rft=lft|1; | |
ll mid=(b+e)>>1; | |
ll p1=query(lft, b, mid, i, j); | |
ll p2=query(rft, mid+1, e, i, j); | |
return p1+p2; | |
} | |
int main() | |
{ | |
FastIO; | |
#ifdef online | |
clock_t tstart = clock(); | |
READ("input.txt"); | |
WRITE("output.txt"); | |
#endif // online | |
ll t=0, q, k, x, n, l, r; | |
while(scl(n) && n){ | |
loop(i, n){ | |
scl(x); | |
arr[i+1]=x; | |
} | |
init(1,1,n); | |
if(t>=1)pf("\n"); | |
pf("Case %lld:\n", ++t); | |
char ch[10]; | |
while(scanf("%s", ch)){ | |
if(!strcmp(ch,"END"))break; | |
scll(l,r); | |
if(ch[0]=='S'){ | |
update(1,1,n,l,r); | |
} | |
else{ | |
x=query(1,1,n,l,r); | |
pf("%lld\n",x); | |
} | |
} | |
} | |
#ifdef online | |
fprintf(stderr, "\n>>Runtime: %.10lf\n", (double)(clock()-tstart)/CLOCKS_PER_SEC); | |
#endif // online | |
return 0; | |
} |
0 Comments