Submission #865137

# Submission time Handle Problem Language Result Execution time Memory
865137 2023-10-24T05:55:00 Z vjudge1 Meteors (POI11_met) C++17
0 / 100
30 ms 65536 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 tl, tm
#define rs 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 = 3e5 + 7;
const int P = 911;
const ll INF = 1e18;

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

int sz, root[N], n, m;

struct node {
	int sum, l, r;
	node() : sum(0), l(0), r(0) {}
} t[20 * N];

void build(int &v, int tl = 1, int tr = m) {
	if (!v) v = ++sz;
	if (tl == tr) return;
	build(t[v].l, ls);
	build(t[v].r, rs);
}

void upd(int pos, int val, int v1, int &v2, int tl = 1, int tr = m) {
	if (v1 != v2) v2 = ++sz;
	if (tl == tr) {
		t[v2].sum = t[v1].sum + val;
		return;
	}
	if (pos <= tm) {
		t[v2].r = t[v1].r;
		upd(pos, val, t[v1].l, t[v2].l, ls);
	} else {
		t[v2].l = t[v1].l;
		upd(pos, val, t[v1].r, t[v2].r, rs);
	}
	int lv = t[v2].l, rv = t[v2].r;
	t[v2].sum = t[lv].sum + t[rv].sum;
}

int get(int r, int v, int tl = 1, int tr = m) {
	if (r < tl) return 0;
	if (tr <= r) return t[v].sum;
	return get(r, t[v].l, ls) + get(r, t[v].r, rs);
}

int nd[N];
vector <int> pos[N];

void GazizMadi() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int x;
		cin >> x;
		pos[x].pb(i);
	}
	for (int i = 1; i <= n; i++) {
		cin >> nd[i];
	}
	int k;
	cin >> k;
	build(root[0]);
	for (int i = 1; i <= k; i++) {
		int l, r, x;
		cin >> l >> r >> x;
		if (l > r) {
			upd(1, x, root[i - 1], root[i]);
			upd(r + 1, -x, root[i], root[i]);
			upd(l, x, root[i], root[i]);
			continue;
		}
		upd(l, x, root[i - 1], root[i]);
		if (r < m) upd(r + 1, -x, root[i], root[i]);
	}
	for (int i = 1; i <= n; i++) {
		int l = 1, r = k;
		while (l <= r) {
			int m = l + r >> 1, ans = 0;
			for (int it: pos[i]) {
				ans += get(it, root[m]);
			}
			if (ans >= nd[i]) r = m - 1;
			else l = m + 1;
		}
		if (l > k) cout << "NIE\n";
		else cout << l << '\n';
	}
}	

const bool Cases = 0;

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

Compilation message

met.cpp: In function 'void build(long long int&, long long int, long long int)':
met.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
met.cpp:14:16: note: in expansion of macro 'tm'
   14 | #define ls tl, tm
      |                ^~
met.cpp:54:16: note: in expansion of macro 'ls'
   54 |  build(t[v].l, ls);
      |                ^~
met.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
met.cpp:15:12: note: in expansion of macro 'tm'
   15 | #define rs tm + 1, tr
      |            ^~
met.cpp:55:16: note: in expansion of macro 'rs'
   55 |  build(t[v].r, rs);
      |                ^~
met.cpp: In function 'void upd(long long int, long long int, long long int, long long int&, long long int, long long int)':
met.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
met.cpp:64:13: note: in expansion of macro 'tm'
   64 |  if (pos <= tm) {
      |             ^~
met.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
met.cpp:14:16: note: in expansion of macro 'tm'
   14 | #define ls tl, tm
      |                ^~
met.cpp:66:35: note: in expansion of macro 'ls'
   66 |   upd(pos, val, t[v1].l, t[v2].l, ls);
      |                                   ^~
met.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
met.cpp:15:12: note: in expansion of macro 'tm'
   15 | #define rs tm + 1, tr
      |            ^~
met.cpp:69:35: note: in expansion of macro 'rs'
   69 |   upd(pos, val, t[v1].r, t[v2].r, rs);
      |                                   ^~
met.cpp: In function 'long long int get(long long int, long long int, long long int, long long int)':
met.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
met.cpp:14:16: note: in expansion of macro 'tm'
   14 | #define ls tl, tm
      |                ^~
met.cpp:78:24: note: in expansion of macro 'ls'
   78 |  return get(r, t[v].l, ls) + get(r, t[v].r, rs);
      |                        ^~
met.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
met.cpp:15:12: note: in expansion of macro 'tm'
   15 | #define rs tm + 1, tr
      |            ^~
met.cpp:78:45: note: in expansion of macro 'rs'
   78 |  return get(r, t[v].l, ls) + get(r, t[v].r, rs);
      |                                             ^~
met.cpp: In function 'void GazizMadi()':
met.cpp:112:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  112 |    int m = l + r >> 1, ans = 0;
      |            ~~^~~
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -