답안 #421740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421740 2021-06-09T11:32:36 Z Kerim Snowball (JOI21_ho_t2) C++17
33 / 100
185 ms 9924 KB
#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<ll,ll> 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 arr[MAXN],w[MAXN],par[MAXN],mx[MAXN],mn[MAXN];
PII rng[3];
const ll I=1e16;
bool intersect(PII a, PII b){
	if(a.ff>b.ff)swap(a,b);
	return (b.ff<=a.ss and a.ss<=b.ss);
}
PII get(int pos,int ind){
	return {arr[pos]+mn[ind],arr[pos]+mx[ind]};
}
int main(){
    //freopen("file.in", "r", stdin);
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
		scanf("%lld",arr+i);
	arr[0]=-I; 
	arr[n+1]=I;
	for(int i=1;i<=q;i++){
		scanf("%lld",w+i);
		par[i]=par[i-1]+w[i];
		mn[i]=min(mn[i-1],par[i]);
		mx[i]=max(mx[i-1],par[i]);
	}
	for(int i=1;i<=n;i++){
		ll A=get(i,q).ff,B=get(i,q).ss;
		if(intersect(get(i-1,q), get(i,q))){
			int st=1,en=q;
			while(st+1<en){
				int mid=(st+en)>>1;
				if(intersect(get(i-1,mid), get(i,mid)))en=mid;
				else st=mid;
			}
			if(intersect(get(i-1,st), get(i,st)))en=st;
			if(w[en]<0)A=get(i-1,en).ss;
			else A=get(i,en).ff;
		}
		if(intersect(get(i+1,q),get(i,q))){
			int st=1,en=q;
			while(st+1<en){
				int mid=(st+en)>>1;
				if(intersect(get(i+1,mid),get(i,mid)))en=mid;
				else st=mid;
			}
			if(intersect(get(i+1,st),get(i,st)))en=st;
			if(w[en]<0)B=get(i,en).ss;
			else B=get(i+1,en).ff;
		}
		printf("%lld\n",B-A);
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%lld",arr+i);
      |   ~~~~~^~~~~~~~~~~~~~
Main.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%lld",w+i);
      |   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 34 ms 6468 KB Output is correct
21 Correct 36 ms 6456 KB Output is correct
22 Correct 32 ms 6552 KB Output is correct
23 Correct 31 ms 6588 KB Output is correct
24 Correct 45 ms 6916 KB Output is correct
25 Correct 181 ms 9924 KB Output is correct
26 Correct 185 ms 9764 KB Output is correct
27 Correct 167 ms 9668 KB Output is correct
28 Correct 177 ms 9668 KB Output is correct
29 Correct 165 ms 9416 KB Output is correct
30 Correct 151 ms 8996 KB Output is correct
31 Correct 110 ms 8608 KB Output is correct
32 Correct 106 ms 8516 KB Output is correct
33 Correct 17 ms 1300 KB Output is correct
34 Correct 170 ms 9744 KB Output is correct
35 Correct 181 ms 9576 KB Output is correct
36 Correct 180 ms 9772 KB Output is correct
37 Correct 170 ms 9628 KB Output is correct
38 Correct 176 ms 9704 KB Output is correct
39 Correct 167 ms 9528 KB Output is correct
40 Correct 111 ms 9544 KB Output is correct
41 Incorrect 36 ms 6580 KB Output isn't correct
42 Halted 0 ms 0 KB -