답안 #940870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940870 2024-03-07T21:03:40 Z qin 3단 점프 (JOI19_jumps) C++17
100 / 100
773 ms 87892 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pn printf("\n")
#define ssize(x) int(x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define bitcount(x) __builtin_popcount(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef double db;
typedef long double ldb;
#define vv vector
/*void read(int &a){
		char c = getchar_unlocked(); a = 0;
		while(c<'0' || '9'<c) c = getchar_unlocked();
		while('0'<=c&&c<='9') a = (a<<3)+(a<<1)+c-'0', c = getchar_unlocked();
}*/
int inf = 2e09; ll infll = 2e18; int mod = (1<<23)*119+1;
int base = 1;
struct seg{
		struct Node{
				int val, p, a;
				Node(){ val = 0, p = 0, a = 0; }
		};
		vv<Node> t;
		void init(int n, vv<int> &tt){
				while(base < n) base <<= 1;
				t.resize(base<<1);
				for(int i = 1; i <= n; ++i) t[i+base-1].a = tt[i];
				for(int i = base-1; i; --i) t[i].a = max(t[i<<1].a, t[i<<1|1].a);
		}
		void add(int i, int val){ t[i].val = max(t[i].val, t[i].a+val), t[i].p = max(t[i].p, val); }
		void push(int i){ if(t[i].p) add(i<<1, t[i].p), add(i<<1|1, t[i].p), t[i].p = 0; }
		void update(int i, int s, int e, int x, int y, int val){
				if(x <= s && e <= y) return void(add(i, val));
				int mid = (s+e)>>1; push(i);
				if(x <= mid) update(i<<1, s, mid, x, y, val);
				if(mid < y) update(i<<1|1, mid+1, e, x, y, val);
				t[i].val = max(t[i<<1].val, t[i<<1|1].val);
		}
		int query(int i, int s, int e, int x, int y){
				if(x <= s && e <= y) return t[i].val;
				int mid = (s+e)>>1, result = 0; push(i);
				if(x <= mid) result = max(result, query(i<<1, s, mid, x, y));
				if(mid < y) result = max(result, query(i<<1|1, mid+1, e, x, y));
				t[i].val = max(t[i<<1].val, t[i<<1|1].val);
				return result;
		}
};
void answer(){
		int n; scanf("%d", &n);
		vv<int> t(n+1);
		for(int i = 1; i <= n; ++i) scanf("%d", &t[i]);
		
		vv<vv<int>> v(n+1); //valid
		vv<int> st; st.emplace_back(n-1);
		for(int i = n-2; i; --i){
				while(ssize(st) && t[st.back()] <= t[i]) v[i].emplace_back(st.back()), st.pop_back();
				if(ssize(st)) v[i].emplace_back(st.back());
				st.emplace_back(i);
		}
		int q; scanf("%d", &q);
		vv<vv<pii>> qr(n+1);
		vv<int> result(q);
		for(int i = 0, a, b; i < q; ++i) scanf("%d%d", &a, &b), qr[a].emplace_back(b, i);
		
		seg seg; seg.init(n, t);
		for(int i = n-2; i; --i){
				for(int &j : v[i]) if(2*j-i <= n) seg.update(1, 1, base, 2*j-i, n, t[i]+t[j]);//, printf("%d %d\n", i, j);
				for(pii &u : qr[i]) result[u.se] = seg.query(1, 1, base, i, u.fi);
		}
		for(int i = 0; i < q; ++i) printf("%d\n", result[i]);
}
signed main(){
		int T = 1;
		//~ scanf("%d", &T);
		//~ ios_base::sync_with_stdio(0); cin.tie(0); //cin >> T;
		for(++T; --T; ) answer();
		return 0;
}

Compilation message

jumps.cpp: In function 'void answer()':
jumps.cpp:59:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   int n; scanf("%d", &n);
      |          ~~~~~^~~~~~~~~~
jumps.cpp:61:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   for(int i = 1; i <= n; ++i) scanf("%d", &t[i]);
      |                               ~~~~~^~~~~~~~~~~~~
jumps.cpp:70:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   int q; scanf("%d", &q);
      |          ~~~~~^~~~~~~~~~
jumps.cpp:73:41: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |   for(int i = 0, a, b; i < q; ++i) scanf("%d%d", &a, &b), qr[a].emplace_back(b, i);
      |                                    ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 214 ms 19500 KB Output is correct
12 Correct 226 ms 19792 KB Output is correct
13 Correct 206 ms 19540 KB Output is correct
14 Correct 231 ms 19412 KB Output is correct
15 Correct 210 ms 19540 KB Output is correct
16 Correct 207 ms 18808 KB Output is correct
17 Correct 208 ms 18772 KB Output is correct
18 Correct 219 ms 18848 KB Output is correct
19 Correct 206 ms 19404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 24988 KB Output is correct
2 Correct 60 ms 25544 KB Output is correct
3 Correct 62 ms 24760 KB Output is correct
4 Correct 104 ms 24912 KB Output is correct
5 Correct 106 ms 24984 KB Output is correct
6 Correct 105 ms 24336 KB Output is correct
7 Correct 106 ms 24224 KB Output is correct
8 Correct 102 ms 24148 KB Output is correct
9 Correct 103 ms 24348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 214 ms 19500 KB Output is correct
12 Correct 226 ms 19792 KB Output is correct
13 Correct 206 ms 19540 KB Output is correct
14 Correct 231 ms 19412 KB Output is correct
15 Correct 210 ms 19540 KB Output is correct
16 Correct 207 ms 18808 KB Output is correct
17 Correct 208 ms 18772 KB Output is correct
18 Correct 219 ms 18848 KB Output is correct
19 Correct 206 ms 19404 KB Output is correct
20 Correct 104 ms 24988 KB Output is correct
21 Correct 60 ms 25544 KB Output is correct
22 Correct 62 ms 24760 KB Output is correct
23 Correct 104 ms 24912 KB Output is correct
24 Correct 106 ms 24984 KB Output is correct
25 Correct 105 ms 24336 KB Output is correct
26 Correct 106 ms 24224 KB Output is correct
27 Correct 102 ms 24148 KB Output is correct
28 Correct 103 ms 24348 KB Output is correct
29 Correct 717 ms 82260 KB Output is correct
30 Correct 644 ms 83496 KB Output is correct
31 Correct 647 ms 81624 KB Output is correct
32 Correct 773 ms 82244 KB Output is correct
33 Correct 735 ms 82120 KB Output is correct
34 Correct 713 ms 80220 KB Output is correct
35 Correct 764 ms 79520 KB Output is correct
36 Correct 735 ms 79700 KB Output is correct
37 Correct 724 ms 81072 KB Output is correct
38 Correct 553 ms 87876 KB Output is correct
39 Correct 526 ms 87892 KB Output is correct
40 Correct 526 ms 84564 KB Output is correct
41 Correct 523 ms 84100 KB Output is correct
42 Correct 527 ms 84104 KB Output is correct
43 Correct 533 ms 85840 KB Output is correct
44 Correct 577 ms 87176 KB Output is correct
45 Correct 553 ms 87236 KB Output is correct
46 Correct 579 ms 84164 KB Output is correct
47 Correct 570 ms 83764 KB Output is correct
48 Correct 555 ms 83644 KB Output is correct
49 Correct 558 ms 85668 KB Output is correct
50 Correct 653 ms 85332 KB Output is correct
51 Correct 633 ms 85300 KB Output is correct
52 Correct 670 ms 82768 KB Output is correct
53 Correct 609 ms 82412 KB Output is correct
54 Correct 621 ms 82512 KB Output is correct
55 Correct 606 ms 84312 KB Output is correct