Submission #889916

# Submission time Handle Problem Language Result Execution time Memory
889916 2023-12-20T09:39:15 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1207 ms 200128 KB
//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define file(s) if(fopen(s".in","r")) freopen(s".in","r",stdin);freopen(s".out","w",stdout)
#define all(x) (x).begin(), (x).end()
#define len(x) (int)x.size()
#define tm (tl + tr >> 1)
#define ls v << 1, tl, tm
#define rs v << 1 | 1, tm + 1, tr
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define elif else if
#define F first
#define S second
#define int long long

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;

const int MOD = 1e9 + 7;
const int N = 2e5 + 7;
const int P = 911;
const ll INF = 1e18;

int rnd() {
	int x = rand() << 15;
	return x ^ rand();
}

pair <int, int> t[N << 2];

pair <int, int> unite(pair <int, int> x, pair <int, int> y) {
	if (x.F > y.F) return x;
	else return y;
}

int n, a[N];

void build(int v = 1, int tl = 1, int tr = n) {
	if (tl == tr) {
		t[v] = {a[tl], tl};
		return;
	}
	build(ls);
	build(rs);
	t[v] = unite(t[v << 1], t[v << 1 | 1]);
}

void upd(int pos, int val, int v = 1, int tl = 1, int tr = n) {
	if (tl == tr) {
		t[v].F = val;
		return;
	}
	if (pos <= tm) upd(pos, val, ls);
	else upd(pos, val, rs);
	t[v] = unite(t[v << 1], t[v << 1 | 1]);
}

pair <int, int> get(int l, int r, int v = 1, int tl = 1, int tr = n) {
	if (l <= tl && tr <= r) return t[v];
	if (r < tl || tr < l) return {-INF, 0};
	return unite(get(l, r, ls), get(l, r, rs));
}

vector <int> g[N];
int old[N], pre[N];

int in(int x) {
	return pre[x];
}

void GazizMadi() {
	set <int> s;
	map <int, int> mp;
	int m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		s.insert(a[i]);
	}
	for (int it: s) {
		mp[it] = len(mp);
	}
	for (int i = 1; i <= n; i++) {
		old[mp[a[i]]] = a[i];
		a[i] = mp[a[i]];
		g[a[i]].pb(i);
	}
	int temp = 1;
	for (int i = 1; i <= n; i++) {
		for (int it: g[i]) {
			// cout << it << ' ' << a[it] << ' ' << old[a[it]] << '\n';
			pre[temp] = old[a[it]];
			a[it] = temp;
			temp++;
		}
	}
	// for (int i = 1; i <= n; i++) {
	// 	cout << a[i] << pre[a[i]] << '\n';
	// }
	// return;
	build();
	while (m--) {
		int l, r, k;
		cin >> l >> r >> k;
		vector <pair <int, int>> del;
		bool ok = 1;
		for (int att = r - l + 1; att; att--) {
			pair <int, int> act = get(l, r);
			del.pb(act);
			int pos = act.S;
			// cout << pos << ' ' << act.F << ' '  << pre[act.F] << '\n';
			if ((pre[act.F] << 1) <= k) {
				// ok = 0; 
				break;
			}
			if (pos < r) {
				pair <int, int> now = get(pos + 1, r);
				if (pre[act.F] + pre[now.F] > k) {
					ok = 0;
					break;
				}
			}
			upd(pos, 0);
		}
		cout << (ok ? 1 : 0) << '\n';
		for (pair <int, int> it: del) {
			upd(it.S, it.F);
		}
	}
}

const bool Cases = 0;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	srand(time(0));
	int TT = 1;
	if (Cases) cin >> TT;
	for (int i = 1; i <= TT; i++) {
		//cout << "Case " << i << ": ";
		GazizMadi();
	}
}

Compilation message

sortbooks.cpp: In function 'void build(long long int, long long int, long long int)':
sortbooks.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
sortbooks.cpp:14:24: note: in expansion of macro 'tm'
   14 | #define ls v << 1, tl, tm
      |                        ^~
sortbooks.cpp:58:8: note: in expansion of macro 'ls'
   58 |  build(ls);
      |        ^~
sortbooks.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
sortbooks.cpp:15:24: note: in expansion of macro 'tm'
   15 | #define rs v << 1 | 1, tm + 1, tr
      |                        ^~
sortbooks.cpp:59:8: note: in expansion of macro 'rs'
   59 |  build(rs);
      |        ^~
sortbooks.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
sortbooks.cpp:68:13: note: in expansion of macro 'tm'
   68 |  if (pos <= tm) upd(pos, val, ls);
      |             ^~
sortbooks.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
sortbooks.cpp:14:24: note: in expansion of macro 'tm'
   14 | #define ls v << 1, tl, tm
      |                        ^~
sortbooks.cpp:68:31: note: in expansion of macro 'ls'
   68 |  if (pos <= tm) upd(pos, val, ls);
      |                               ^~
sortbooks.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
sortbooks.cpp:15:24: note: in expansion of macro 'tm'
   15 | #define rs v << 1 | 1, tm + 1, tr
      |                        ^~
sortbooks.cpp:69:21: note: in expansion of macro 'rs'
   69 |  else upd(pos, val, rs);
      |                     ^~
sortbooks.cpp: In function 'std::pair<long long int, long long int> get(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
sortbooks.cpp:14:24: note: in expansion of macro 'tm'
   14 | #define ls v << 1, tl, tm
      |                        ^~
sortbooks.cpp:76:25: note: in expansion of macro 'ls'
   76 |  return unite(get(l, r, ls), get(l, r, rs));
      |                         ^~
sortbooks.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
sortbooks.cpp:15:24: note: in expansion of macro 'tm'
   15 | #define rs v << 1 | 1, tm + 1, tr
      |                        ^~
sortbooks.cpp:76:40: note: in expansion of macro 'rs'
   76 |  return unite(get(l, r, ls), get(l, r, rs));
      |                                        ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Incorrect 2 ms 10588 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Incorrect 2 ms 10588 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1207 ms 200128 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 16612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Incorrect 2 ms 10588 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Incorrect 2 ms 10588 KB Output isn't correct
4 Halted 0 ms 0 KB -