Submission #340316

#TimeUsernameProblemLanguageResultExecution timeMemory
340316KerimFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
415 ms15084 KiB
#include "bits/stdc++.h" #define MAXN 200009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} ll s[MAXN<<2],ans; int arr[MAXN],n,q,sa,t; void inc(int l,int r,int v,int nd=1,int x=1,int y=n){ if(l>y or x>r)return; if(l<=x and y<=r){s[nd]+=v;return;} int mid=(x+y)>>1; inc(l,r,v,nd<<1,x,mid);inc(l,r,v,nd<<1|1,mid+1,y); } ll get(int p,int nd=1,int x=1,int y=n){ if(!p)return 0LL; if(x==y)return s[nd]+arr[x]; int mid=(x+y)>>1; if(p<=mid)return s[nd]+get(p,nd<<1,x,mid); return s[nd]+get(p,nd<<1|1,mid+1,y); } ll cost(int p){ ll a=get(p),b=get(p+1); if(a<b) return sa*(a-b); return t*(a-b); } int main(){ //freopen("dreaming.in", "r", stdin); scanf("%d%d%d%d",&n,&q,&sa,&t); for(int i=0;i<=n;i++)scanf("%d",arr+i); for(int i=0;i<n;i++)ans+=cost(i); while(q--){ int l,r,x; scanf("%d%d%d",&l,&r,&x); ans-=cost(l-1);if(r<n)ans-=cost(r); inc(l,r,x); ans+=cost(l-1);if(r<n)ans+=cost(r); printf("%lld\n",ans); } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |     scanf("%d%d%d%d",&n,&q,&sa,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:44:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     for(int i=0;i<=n;i++)scanf("%d",arr+i);
      |                          ~~~~~^~~~~~~~~~~~
foehn_phenomena.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |   scanf("%d%d%d",&l,&r,&x);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...