답안 #444072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444072 2021-07-13T04:51:21 Z jamezzz Snowball (JOI21_ho_t2) C++17
100 / 100
171 ms 16832 KB
#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;

typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements

#define DEBUG

#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define maxn 200005

int n,q;
ll x[maxn],w[maxn],p[maxn],mx[maxn],mn[maxn],t[maxn];

int main(){
	sf("%d%d",&n,&q);
	for(int i=0;i<n;++i){
		sf("%lld",&x[i]);
	}
	for(int i=1;i<=q;++i){
		sf("%lld",&w[i]);
		p[i]=p[i-1]+w[i];
		mx[i]=max(mx[i-1],p[i]);
		mn[i]=min(mn[i-1],p[i]);
	}
	for(int i=0;i<n;++i){
		if(i!=0&&x[i-1]+mx[q]>x[i]+mn[q]){
			int lo=0,hi=q,mid,res=q;
			while(lo<=hi){
				mid=(lo+hi)/2;
				if(x[i-1]+mx[mid]<=x[i]+mn[mid])lo=mid+1;
				else res=mid,hi=mid-1;
			}
			if(mn[res]==mn[res-1])t[i]+=-mn[res];
			else t[i]+=x[i]-(x[i-1]+mx[res]);
		}
		else t[i]+=-mn[q];
		if(i!=n-1&&x[i]+mx[q]>x[i+1]+mn[q]){
			int lo=0,hi=q,mid,res=q;
			while(lo<=hi){
				mid=(lo+hi)/2;
				if(x[i]+mx[mid]<=x[i+1]+mn[mid])lo=mid+1;
				else res=mid,hi=mid-1;
			}
			if(mx[res]==mx[res-1])t[i]+=mx[res];
			else t[i]+=x[i+1]+mn[res]-x[i];
		}
		else t[i]+=mx[q];
	}
	for(int i=0;i<n;++i){
		pf("%lld\n",t[i]);
	}
}


Compilation message

Main.cpp: In function 'int main()':
Main.cpp:47:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  sf("%d%d",&n,&q);
      |    ^
Main.cpp:49:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   sf("%lld",&x[i]);
      |     ^
Main.cpp:52:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   sf("%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 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 304 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 460 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 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 304 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 36 ms 8580 KB Output is correct
21 Correct 43 ms 8436 KB Output is correct
22 Correct 35 ms 8220 KB Output is correct
23 Correct 34 ms 8164 KB Output is correct
24 Correct 43 ms 8580 KB Output is correct
25 Correct 152 ms 14980 KB Output is correct
26 Correct 158 ms 14800 KB Output is correct
27 Correct 150 ms 14536 KB Output is correct
28 Correct 171 ms 14664 KB Output is correct
29 Correct 152 ms 14148 KB Output is correct
30 Correct 139 ms 13704 KB Output is correct
31 Correct 91 ms 13168 KB Output is correct
32 Correct 78 ms 13128 KB Output is correct
33 Correct 14 ms 1780 KB Output is correct
34 Correct 153 ms 15300 KB Output is correct
35 Correct 150 ms 14660 KB Output is correct
36 Correct 152 ms 14916 KB Output is correct
37 Correct 158 ms 14692 KB Output is correct
38 Correct 157 ms 14612 KB Output is correct
39 Correct 145 ms 14708 KB Output is correct
40 Correct 99 ms 14660 KB Output is correct
41 Correct 38 ms 9248 KB Output is correct
42 Correct 73 ms 13156 KB Output is correct
43 Correct 116 ms 16432 KB Output is correct
44 Correct 36 ms 9148 KB Output is correct
45 Correct 94 ms 14748 KB Output is correct
46 Correct 107 ms 16576 KB Output is correct
47 Correct 110 ms 16800 KB Output is correct
48 Correct 142 ms 16832 KB Output is correct