Submission #716871

# Submission time Handle Problem Language Result Execution time Memory
716871 2023-03-31T08:47:01 Z Baytoro Snowball (JOI21_ho_t2) C++17
100 / 100
539 ms 26452 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=2e5+5;
void solve(){
	int n,q;cin>>n>>q;
	vector<int> a(n+2);
	a[0]=-INF,a[n+1]=INF;
	for(int i=1;i<=n;i++) cin>>a[i];
	vector<int> querys(q+1),mn(q+1),mx(q+1);
	set<pair<int,int>> st;
	for(int i=1;i<=q;i++){
		cin>>querys[i];
		querys[i]+=querys[i-1];
		mx[i]=max(mx[i-1],querys[i]);
		mn[i]=min(mn[i-1],querys[i]);
		st.insert({mx[i]-mn[i],i});
	}
	for(int i=1;i<=n;i++){
		int A=a[i]-a[i-1];
		int B=a[i+1]-a[i];
		int ans=0;
		auto it=st.lower_bound({A,0});
		if(it==st.end()) ans-=mn[q];
		else{
			int j=(*it).sc;
			ans+=(querys[j]>querys[j-1]? -mn[j] : A-mx[j]);
		}
		it=st.lower_bound({B,0});
		if(it==st.end()) ans+=mx[q];
		else{
			int j=(*it).sc;
			ans+=(querys[j]<querys[j-1]? mx[j] : B+mn[j]);
		}
		cout<<ans<<endl;
	}
}
main(){
	//fopn("team");
	//ios;
	int T=1;
	//cin>>T;
	for(int i=1;i<=T;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Compilation message

Main.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main(){
      | ^~~~
Main.cpp: In function 'void fopn(std::string)':
Main.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 4 ms 436 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 3 ms 436 KB Output is correct
11 Correct 2 ms 440 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 444 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 4 ms 436 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 3 ms 436 KB Output is correct
11 Correct 2 ms 440 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 444 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 138 ms 19608 KB Output is correct
21 Correct 130 ms 19372 KB Output is correct
22 Correct 125 ms 19148 KB Output is correct
23 Correct 117 ms 19020 KB Output is correct
24 Correct 138 ms 19396 KB Output is correct
25 Correct 424 ms 24368 KB Output is correct
26 Correct 448 ms 24240 KB Output is correct
27 Correct 403 ms 24028 KB Output is correct
28 Correct 417 ms 24156 KB Output is correct
29 Correct 432 ms 23576 KB Output is correct
30 Correct 310 ms 23188 KB Output is correct
31 Correct 220 ms 22448 KB Output is correct
32 Correct 224 ms 22724 KB Output is correct
33 Correct 32 ms 2764 KB Output is correct
34 Correct 388 ms 24820 KB Output is correct
35 Correct 421 ms 24128 KB Output is correct
36 Correct 539 ms 24384 KB Output is correct
37 Correct 469 ms 24100 KB Output is correct
38 Correct 432 ms 23916 KB Output is correct
39 Correct 357 ms 24180 KB Output is correct
40 Correct 249 ms 24140 KB Output is correct
41 Correct 145 ms 20136 KB Output is correct
42 Correct 236 ms 22580 KB Output is correct
43 Correct 282 ms 25932 KB Output is correct
44 Correct 147 ms 20144 KB Output is correct
45 Correct 261 ms 24056 KB Output is correct
46 Correct 279 ms 26000 KB Output is correct
47 Correct 301 ms 26452 KB Output is correct
48 Correct 303 ms 26324 KB Output is correct