답안 #552857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
552857 2022-04-24T07:49:39 Z cheetose 3단 점프 (JOI19_jumps) C++17
100 / 100
1075 ms 104108 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

ll a[500001],tree[1050000],lazy[1050000],mx[1050000];
void init(int node,int S,int E){
	tree[node]=-INF;
	if(S==E){
		mx[node]=a[S];
		return;
	}
	init(2*node,S,(S+E)/2);
	init(2*node+1,(S+E)/2+1,E);
	mx[node]=max(mx[2*node],mx[2*node+1]);
}
void propagation(int node,int S,int E){
	if(lazy[node]!=0){
		tree[node]=max(tree[node],lazy[node]+mx[node]);
		if(S!=E){
			lazy[2*node]=max(lazy[node*2],lazy[node]);
			lazy[2*node+1]=max(lazy[node*2+1],lazy[node]);
		}
		lazy[node]=0;
	}
}
void upd(int node,int S,int E,int i,int j,ll val){
	propagation(node,S,E);
	if(i>E || j<S) return;
	if(j>=E && i<=S){
		lazy[node]=max(lazy[node],val);
		propagation(node,S,E);
		return;
	}
	upd(2*node,S,(S+E)/2,i,j,val);
	upd(2*node+1,(S+E)/2+1,E,i,j,val);
	tree[node]=max(tree[2*node],tree[2*node+1]);
}
ll find(int node,int S,int E,int i,int j){
	propagation(node,S,E);
	if(i>E || j<S)return 0;
	if(j>=E && i<=S)return tree[node];
	return max(find(node*2,S,(S+E)/2,i,j),find(2*node+1,(S+E)/2+1,E,i,j));
}
ll ans[500005];
Vi v[500005];
VPi Q[500005];
int main(){
	int n;
	scanf("%d",&n);
	fup(i,1,n,1)scanf("%lld",a+i);
	Vi st;
	fup(i,1,n,1){
		while(!st.empty() && a[st.back()]<a[i]){
			v[st.back()].pb(i);
			st.pop_back();
		}
		if(!st.empty()){
			v[st.back()].pb(i);
		}
		st.pb(i);
	}
	init(1,1,n);
	int q;
	scanf("%d",&q);
	fup(i,0,q-1,1){
		int x,y;
		scanf("%d%d",&x,&y);
		Q[x].pb(mp(y,i));
	}
	fdn(i,n,1,1){
		for(int j:v[i]){
			upd(1,1,n,2*j-i,n,a[i]+a[j]);
		}
		for(auto [j,I]:Q[i]){
			ans[I]=find(1,1,n,i,j);
		}
	}
	fup(i,0,q-1,1)printf("%lld\n",ans[i]);
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
jumps.cpp:88:2: note: in expansion of macro 'fup'
   88 |  fup(i,1,n,1)scanf("%lld",a+i);
      |  ^~~
jumps.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
jumps.cpp:90:2: note: in expansion of macro 'fup'
   90 |  fup(i,1,n,1){
      |  ^~~
jumps.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
jumps.cpp:103:2: note: in expansion of macro 'fup'
  103 |  fup(i,0,q-1,1){
      |  ^~~
jumps.cpp:11:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   11 | #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
      |                              ^
jumps.cpp:108:2: note: in expansion of macro 'fdn'
  108 |  fdn(i,n,1,1){
      |  ^~~
jumps.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
jumps.cpp:116:2: note: in expansion of macro 'fup'
  116 |  fup(i,0,q-1,1)printf("%lld\n",ans[i]);
      |  ^~~
jumps.cpp:87:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
jumps.cpp:88:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |  fup(i,1,n,1)scanf("%lld",a+i);
      |              ~~~~~^~~~~~~~~~~~
jumps.cpp:102:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
jumps.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 13 ms 23788 KB Output is correct
3 Correct 13 ms 23792 KB Output is correct
4 Correct 13 ms 23792 KB Output is correct
5 Correct 12 ms 23732 KB Output is correct
6 Correct 12 ms 23836 KB Output is correct
7 Correct 12 ms 23792 KB Output is correct
8 Correct 14 ms 23764 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 13 ms 23788 KB Output is correct
3 Correct 13 ms 23792 KB Output is correct
4 Correct 13 ms 23792 KB Output is correct
5 Correct 12 ms 23732 KB Output is correct
6 Correct 12 ms 23836 KB Output is correct
7 Correct 12 ms 23792 KB Output is correct
8 Correct 14 ms 23764 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 323 ms 44932 KB Output is correct
12 Correct 310 ms 44876 KB Output is correct
13 Correct 300 ms 44824 KB Output is correct
14 Correct 298 ms 44912 KB Output is correct
15 Correct 307 ms 44920 KB Output is correct
16 Correct 315 ms 44492 KB Output is correct
17 Correct 304 ms 44232 KB Output is correct
18 Correct 306 ms 44324 KB Output is correct
19 Correct 300 ms 44932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 45912 KB Output is correct
2 Correct 96 ms 45644 KB Output is correct
3 Correct 95 ms 46396 KB Output is correct
4 Correct 163 ms 45848 KB Output is correct
5 Correct 159 ms 45896 KB Output is correct
6 Correct 157 ms 45132 KB Output is correct
7 Correct 155 ms 45028 KB Output is correct
8 Correct 164 ms 45132 KB Output is correct
9 Correct 159 ms 45420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 13 ms 23788 KB Output is correct
3 Correct 13 ms 23792 KB Output is correct
4 Correct 13 ms 23792 KB Output is correct
5 Correct 12 ms 23732 KB Output is correct
6 Correct 12 ms 23836 KB Output is correct
7 Correct 12 ms 23792 KB Output is correct
8 Correct 14 ms 23764 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 323 ms 44932 KB Output is correct
12 Correct 310 ms 44876 KB Output is correct
13 Correct 300 ms 44824 KB Output is correct
14 Correct 298 ms 44912 KB Output is correct
15 Correct 307 ms 44920 KB Output is correct
16 Correct 315 ms 44492 KB Output is correct
17 Correct 304 ms 44232 KB Output is correct
18 Correct 306 ms 44324 KB Output is correct
19 Correct 300 ms 44932 KB Output is correct
20 Correct 162 ms 45912 KB Output is correct
21 Correct 96 ms 45644 KB Output is correct
22 Correct 95 ms 46396 KB Output is correct
23 Correct 163 ms 45848 KB Output is correct
24 Correct 159 ms 45896 KB Output is correct
25 Correct 157 ms 45132 KB Output is correct
26 Correct 155 ms 45028 KB Output is correct
27 Correct 164 ms 45132 KB Output is correct
28 Correct 159 ms 45420 KB Output is correct
29 Correct 1075 ms 98408 KB Output is correct
30 Correct 923 ms 97776 KB Output is correct
31 Correct 912 ms 99656 KB Output is correct
32 Correct 1062 ms 98324 KB Output is correct
33 Correct 1073 ms 98340 KB Output is correct
34 Correct 1069 ms 96132 KB Output is correct
35 Correct 1063 ms 95680 KB Output is correct
36 Correct 1055 ms 95808 KB Output is correct
37 Correct 1070 ms 97176 KB Output is correct
38 Correct 761 ms 104000 KB Output is correct
39 Correct 756 ms 104108 KB Output is correct
40 Correct 749 ms 100568 KB Output is correct
41 Correct 751 ms 100232 KB Output is correct
42 Correct 745 ms 100228 KB Output is correct
43 Correct 757 ms 101852 KB Output is correct
44 Correct 797 ms 103372 KB Output is correct
45 Correct 824 ms 103428 KB Output is correct
46 Correct 770 ms 100296 KB Output is correct
47 Correct 786 ms 99784 KB Output is correct
48 Correct 791 ms 99808 KB Output is correct
49 Correct 784 ms 101984 KB Output is correct
50 Correct 891 ms 101444 KB Output is correct
51 Correct 870 ms 101512 KB Output is correct
52 Correct 854 ms 99020 KB Output is correct
53 Correct 842 ms 98768 KB Output is correct
54 Correct 861 ms 98876 KB Output is correct
55 Correct 875 ms 100328 KB Output is correct