답안 #890335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890335 2023-12-21T03:42:07 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
1607 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
// #pragma GCC optimize("Ofast,unroll-loops,fast-math")
// #pragma GCC target("popcnt")


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
 
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back

const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353;  // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const int N = ll(2e6)+10;
const long long inf = 2e18;
const long double eps = 1e-15L;
 
ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; }

ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;}


void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }

int n, m, a[N], u[N], sta[24][N], LOG[N], ans[N];
int ql[N], qr[N], qk[N];
vector<int> q[N];

int getmx (int l, int r) {
	if(l > r) return 0;
	int j = LOG[r - l + 1];
	return max(sta[j][l], sta[j][r-(1<<j)+1]);
}

struct tre {
	int mx, ans;
} t[N * 4];

tre combine(tre a, tre b) {
	tre c; 
	c.mx = max(a.mx, b.mx);
	c.ans = max(a.ans, b.ans);
	return c;
}

void build(int v, int tl, int tr) {
	u[v] = -1;
	if(tl == tr) {
		t[v] = {a[tl], 0};
		return;
	}
	int tm = (tl + tr) / 2;
	build(v + v, tl, tm);
	build(v + v + 1, tm + 1, tr);
	t[v] = combine(t[v + v], t[v + v + 1]);
}

void push(int v, int tl, int tr){
	if(u[v] != -1) {
		t[v].ans = t[v].mx + u[v];
		if(tl != tr) {
			u[v + v] = u[v];
			u[v + v + 1] = u[v];
		}
		u[v] = -1;
	}
} 

void update(int v, int tl, int tr, int l, int r, int x) {
	push(v, tl, tr);
	if(tl > r || l > tr) return;
	if(l <= tl && tr <= r) {
		u[v] = x;
		push(v, tl, tr);
		return;
	}
	int tm = (tl + tr) / 2;
	update(v + v, tl, tm, l, r, x);
	update(v + v + 1, tm + 1, tr, l, r, x);
	t[v] = combine(t[v + v], t[v + v + 1]);
}

tre get(int v, int tl, int tr, int l, int r) {
	push(v, tl, tr);
	if(tl > r || l > tr) return {0, 0};
	if(l <= tl && tr <= r) return t[v];
	int tm = (tl + tr) / 2;
	return combine(get(v + v, tl, tm, l, r), get(v + v + 1, tm + 1, tr, l, r));
}

void Baizho() {	
	for(int i = 2; i < N; i ++) LOG[i] = LOG[i / 2] + 1;
	cin>>n>>m;
	for(int i = 1; i <= n; i ++) {
		cin>>a[i];
		sta[0][i] = a[i];
	}
	build(1, 1, n);
	for(int j = 1; j <= 20; j ++) {
		for(int i = 1; i+(1<<j)-1 <= n; i ++) {
			sta[j][i] = max(sta[j-1][i], sta[j-1][i+(1<<j-1)]);
		}
	}
	for(int i = 1; i <= m; i ++) {
		cin>>ql[i]>>qr[i]>>qk[i];
		q[ql[i]].pb(i);
	}
	for(int i = n; i >= 1; i --) {
		int l = i + 1, r = i;
		int bl = i + 1, br = n;
		while(bl <= br) {
			int mid = (bl + br) / 2;
			if(getmx(i + 1, mid) < a[i]) bl = mid + 1, r = mid;
			else br = mid - 1;
		}
		if(l <= r) {
			update(1, 1, n, l, r, a[i]);
//			cout<<i<<" "<<l<<" "<<r<<"\n";
		}
		for(auto j : q[i]) {
			ans[j] = (get(1, 1, n, ql[j], qr[j]).ans <= qk[j]);
		}
	}
	for(int i = 1; i <= m; i ++) cout<<ans[i]<<"\n";
	
}
 
signed main() {		
 
    ios_base::sync_with_stdio(false);   
    cin.tie(0);cout.tie(0); 
//   	precalc();
   	
    int ttt = 1;
//    cin>>ttt;

    for(int i=1; i<=ttt; i++) { Baizho(); }
}

Compilation message

sortbooks.cpp: In function 'void Baizho()':
sortbooks.cpp:113:49: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
  113 |    sta[j][i] = max(sta[j-1][i], sta[j-1][i+(1<<j-1)]);
      |                                                ~^~
sortbooks.cpp: In function 'void Freopen(std::string)':
sortbooks.cpp:35:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:35:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                                                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 73052 KB Output is correct
2 Correct 14 ms 68844 KB Output is correct
3 Correct 16 ms 83292 KB Output is correct
4 Correct 15 ms 79292 KB Output is correct
5 Correct 16 ms 83292 KB Output is correct
6 Correct 16 ms 85592 KB Output is correct
7 Correct 16 ms 85340 KB Output is correct
8 Correct 17 ms 85336 KB Output is correct
9 Correct 16 ms 85340 KB Output is correct
10 Correct 16 ms 85476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 73052 KB Output is correct
2 Correct 14 ms 68844 KB Output is correct
3 Correct 16 ms 83292 KB Output is correct
4 Correct 15 ms 79292 KB Output is correct
5 Correct 16 ms 83292 KB Output is correct
6 Correct 16 ms 85592 KB Output is correct
7 Correct 16 ms 85340 KB Output is correct
8 Correct 17 ms 85336 KB Output is correct
9 Correct 16 ms 85340 KB Output is correct
10 Correct 16 ms 85476 KB Output is correct
11 Correct 19 ms 89588 KB Output is correct
12 Correct 20 ms 93860 KB Output is correct
13 Correct 22 ms 93764 KB Output is correct
14 Correct 21 ms 93788 KB Output is correct
15 Correct 22 ms 93788 KB Output is correct
16 Correct 20 ms 93784 KB Output is correct
17 Correct 20 ms 93788 KB Output is correct
18 Correct 19 ms 93788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1607 ms 262144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 116776 KB Output is correct
2 Correct 103 ms 115476 KB Output is correct
3 Correct 97 ms 116040 KB Output is correct
4 Correct 100 ms 116304 KB Output is correct
5 Correct 100 ms 116308 KB Output is correct
6 Correct 78 ms 115064 KB Output is correct
7 Correct 81 ms 115024 KB Output is correct
8 Correct 87 ms 115656 KB Output is correct
9 Correct 45 ms 90060 KB Output is correct
10 Correct 85 ms 115664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 73052 KB Output is correct
2 Correct 14 ms 68844 KB Output is correct
3 Correct 16 ms 83292 KB Output is correct
4 Correct 15 ms 79292 KB Output is correct
5 Correct 16 ms 83292 KB Output is correct
6 Correct 16 ms 85592 KB Output is correct
7 Correct 16 ms 85340 KB Output is correct
8 Correct 17 ms 85336 KB Output is correct
9 Correct 16 ms 85340 KB Output is correct
10 Correct 16 ms 85476 KB Output is correct
11 Correct 19 ms 89588 KB Output is correct
12 Correct 20 ms 93860 KB Output is correct
13 Correct 22 ms 93764 KB Output is correct
14 Correct 21 ms 93788 KB Output is correct
15 Correct 22 ms 93788 KB Output is correct
16 Correct 20 ms 93784 KB Output is correct
17 Correct 20 ms 93788 KB Output is correct
18 Correct 19 ms 93788 KB Output is correct
19 Correct 246 ms 132900 KB Output is correct
20 Correct 246 ms 132948 KB Output is correct
21 Correct 200 ms 130732 KB Output is correct
22 Correct 206 ms 130696 KB Output is correct
23 Correct 199 ms 130644 KB Output is correct
24 Correct 168 ms 130388 KB Output is correct
25 Correct 169 ms 130596 KB Output is correct
26 Correct 186 ms 131412 KB Output is correct
27 Correct 188 ms 131244 KB Output is correct
28 Correct 197 ms 131668 KB Output is correct
29 Correct 210 ms 132928 KB Output is correct
30 Correct 227 ms 132948 KB Output is correct
31 Correct 218 ms 132784 KB Output is correct
32 Correct 218 ms 132948 KB Output is correct
33 Correct 230 ms 132948 KB Output is correct
34 Correct 156 ms 130100 KB Output is correct
35 Correct 159 ms 130104 KB Output is correct
36 Correct 154 ms 130136 KB Output is correct
37 Correct 155 ms 130168 KB Output is correct
38 Correct 158 ms 130132 KB Output is correct
39 Correct 192 ms 131536 KB Output is correct
40 Correct 142 ms 125016 KB Output is correct
41 Correct 179 ms 131532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 73052 KB Output is correct
2 Correct 14 ms 68844 KB Output is correct
3 Correct 16 ms 83292 KB Output is correct
4 Correct 15 ms 79292 KB Output is correct
5 Correct 16 ms 83292 KB Output is correct
6 Correct 16 ms 85592 KB Output is correct
7 Correct 16 ms 85340 KB Output is correct
8 Correct 17 ms 85336 KB Output is correct
9 Correct 16 ms 85340 KB Output is correct
10 Correct 16 ms 85476 KB Output is correct
11 Correct 19 ms 89588 KB Output is correct
12 Correct 20 ms 93860 KB Output is correct
13 Correct 22 ms 93764 KB Output is correct
14 Correct 21 ms 93788 KB Output is correct
15 Correct 22 ms 93788 KB Output is correct
16 Correct 20 ms 93784 KB Output is correct
17 Correct 20 ms 93788 KB Output is correct
18 Correct 19 ms 93788 KB Output is correct
19 Incorrect 1607 ms 262144 KB Output isn't correct
20 Halted 0 ms 0 KB -