Submission #29398

# Submission time Handle Problem Language Result Execution time Memory
29398 2017-07-19T08:31:17 Z PrOAhMeT Foehn Phenomena (JOI17_foehn_phenomena) C++14
100 / 100
329 ms 5924 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;

const int MAXN=200015;
int n,q,a[MAXN];
LL s,tt;

struct fenwick_tree {
	
	LL fen[MAXN];

	void upd(int x,LL y) {

		++x;
		for(;x<MAXN;x+=x&(-x))
			fen[x]+=y;

	}

	LL get(int x) {

		++x;
		LL ret=0;
		for(;x;x-=x&(-x))
			ret+=fen[x];
		return ret;

	}

} h,t;

int main() {

	scanf("%d %d %lld %lld",&n,&q,&s,&tt);
	LL temp=0;
	for(int i=0;i<=n;++i) {
		scanf("%d",&a[i]);
		if(i>0) {
			if(a[i]>a[i-1]) {
				t.upd(i,-s*(a[i]-a[i-1]));
			}
			else {
				t.upd(i,tt*(a[i-1]-a[i]));
			}
		}
		if(i) h.upd(i,a[i]-a[i-1]);
		else h.upd(i,a[i]);
	}
	int l,r,x;
	LL bef,cur,beft,curt,nw;
	for(int i=0;i<q;++i) {
		scanf("%d %d %d",&l,&r,&x);
		LL oldl,oldr;
		if(l>0)
			oldl=t.get(l)-t.get(l-1);
		if(r<n)
			oldr=t.get(r+1)-t.get(r);
		h.upd(l,x);
		h.upd(r+1,-x);
		if(l>0) {
			bef=h.get(l-1);
			cur=h.get(l);
			if(bef>cur) {
				t.upd(l,tt*(bef-cur)-oldl);
			}
			else t.upd(l,-s*(cur-bef)-oldl);
		}
		if(r<n) {
			bef=h.get(r);
			cur=h.get(r+1);
			if(cur<bef) {
				t.upd(r+1,tt*(bef-cur)-oldr);
			}
			else t.upd(r+1,-s*(cur-bef)-oldr);
		}
		//cout<<"update "<<i+1<<endl;
		//for(int j=0;j<=n;++j)
			//cout<<j<<" "<<t.get(j)<<" "<<h.get(j)<<endl;
		//printf("1\n");
		printf("%lld\n",t.get(n));
	}

}

Compilation message

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:42:5: warning: unused variable 'temp' [-Wunused-variable]
  LL temp=0;
     ^
foehn_phenomena.cpp:57:13: warning: unused variable 'beft' [-Wunused-variable]
  LL bef,cur,beft,curt,nw;
             ^
foehn_phenomena.cpp:57:18: warning: unused variable 'curt' [-Wunused-variable]
  LL bef,cur,beft,curt,nw;
                  ^
foehn_phenomena.cpp:57:23: warning: unused variable 'nw' [-Wunused-variable]
  LL bef,cur,beft,curt,nw;
                       ^
foehn_phenomena.cpp:41:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %lld %lld",&n,&q,&s,&tt);
                                       ^
foehn_phenomena.cpp:44:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
                    ^
foehn_phenomena.cpp:59:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&l,&r,&x);
                             ^
foehn_phenomena.cpp:73:14: warning: 'oldl' may be used uninitialized in this function [-Wmaybe-uninitialized]
    else t.upd(l,-s*(cur-bef)-oldl);
              ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5924 KB Output is correct
2 Correct 0 ms 5924 KB Output is correct
3 Correct 0 ms 5924 KB Output is correct
4 Correct 0 ms 5924 KB Output is correct
5 Correct 0 ms 5924 KB Output is correct
6 Correct 3 ms 5924 KB Output is correct
7 Correct 0 ms 5924 KB Output is correct
8 Correct 0 ms 5924 KB Output is correct
9 Correct 3 ms 5924 KB Output is correct
10 Correct 3 ms 5924 KB Output is correct
11 Correct 0 ms 5924 KB Output is correct
12 Correct 3 ms 5924 KB Output is correct
13 Correct 0 ms 5924 KB Output is correct
14 Correct 0 ms 5924 KB Output is correct
15 Correct 0 ms 5924 KB Output is correct
16 Correct 3 ms 5924 KB Output is correct
17 Correct 0 ms 5924 KB Output is correct
18 Correct 0 ms 5924 KB Output is correct
19 Correct 0 ms 5924 KB Output is correct
20 Correct 0 ms 5924 KB Output is correct
21 Correct 0 ms 5924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 313 ms 5924 KB Output is correct
2 Correct 273 ms 5924 KB Output is correct
3 Correct 283 ms 5924 KB Output is correct
4 Correct 299 ms 5924 KB Output is correct
5 Correct 309 ms 5924 KB Output is correct
6 Correct 206 ms 5924 KB Output is correct
7 Correct 169 ms 5924 KB Output is correct
8 Correct 289 ms 5924 KB Output is correct
9 Correct 316 ms 5924 KB Output is correct
10 Correct 309 ms 5924 KB Output is correct
11 Correct 163 ms 5924 KB Output is correct
12 Correct 149 ms 5924 KB Output is correct
13 Correct 153 ms 5924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5924 KB Output is correct
2 Correct 0 ms 5924 KB Output is correct
3 Correct 0 ms 5924 KB Output is correct
4 Correct 0 ms 5924 KB Output is correct
5 Correct 0 ms 5924 KB Output is correct
6 Correct 3 ms 5924 KB Output is correct
7 Correct 0 ms 5924 KB Output is correct
8 Correct 0 ms 5924 KB Output is correct
9 Correct 3 ms 5924 KB Output is correct
10 Correct 3 ms 5924 KB Output is correct
11 Correct 0 ms 5924 KB Output is correct
12 Correct 3 ms 5924 KB Output is correct
13 Correct 0 ms 5924 KB Output is correct
14 Correct 0 ms 5924 KB Output is correct
15 Correct 0 ms 5924 KB Output is correct
16 Correct 3 ms 5924 KB Output is correct
17 Correct 0 ms 5924 KB Output is correct
18 Correct 0 ms 5924 KB Output is correct
19 Correct 0 ms 5924 KB Output is correct
20 Correct 0 ms 5924 KB Output is correct
21 Correct 0 ms 5924 KB Output is correct
22 Correct 313 ms 5924 KB Output is correct
23 Correct 273 ms 5924 KB Output is correct
24 Correct 283 ms 5924 KB Output is correct
25 Correct 299 ms 5924 KB Output is correct
26 Correct 309 ms 5924 KB Output is correct
27 Correct 206 ms 5924 KB Output is correct
28 Correct 169 ms 5924 KB Output is correct
29 Correct 289 ms 5924 KB Output is correct
30 Correct 316 ms 5924 KB Output is correct
31 Correct 309 ms 5924 KB Output is correct
32 Correct 163 ms 5924 KB Output is correct
33 Correct 149 ms 5924 KB Output is correct
34 Correct 153 ms 5924 KB Output is correct
35 Correct 273 ms 5924 KB Output is correct
36 Correct 276 ms 5924 KB Output is correct
37 Correct 226 ms 5924 KB Output is correct
38 Correct 329 ms 5924 KB Output is correct
39 Correct 179 ms 5924 KB Output is correct
40 Correct 196 ms 5924 KB Output is correct
41 Correct 206 ms 5924 KB Output is correct
42 Correct 326 ms 5924 KB Output is correct
43 Correct 316 ms 5924 KB Output is correct
44 Correct 256 ms 5924 KB Output is correct
45 Correct 309 ms 5924 KB Output is correct
46 Correct 216 ms 5924 KB Output is correct
47 Correct 186 ms 5924 KB Output is correct
48 Correct 173 ms 5924 KB Output is correct
49 Correct 279 ms 5924 KB Output is correct
50 Correct 146 ms 5924 KB Output is correct
51 Correct 193 ms 5924 KB Output is correct
52 Correct 203 ms 5924 KB Output is correct