답안 #865153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865153 2023-10-24T06:05:36 Z vjudge1 Meteors (POI11_met) C++
24 / 100
59 ms 35636 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

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 = 4e4 + 7;
const int P = 911;
const ll INF = 1e18;

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

struct node {
	ll sum;
	int 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 || tl != 1 || tr != m) 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;
}

ll res = 0;

void get(int r, int v, int tl = 1, int tr = m) {
	if (r < tl) return;
	if (tr <= r) {
		res += 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;
	int x;
	for (int i = 1; i <= m; i++) {
		cin >> x;
		pos[x].pb(i);
	}
	for (int i = 1; i <= n; i++) {
		cin >> nd[i];
	}
	int k;
	cin >> k;
	build(root[0]);
	int l, r;
	for (int i = 1; i <= k; i++) {
		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]);
	}
	int m;
	for (int i = 1; i <= n; i++) {
		l = 1; 
		r = k;
		while (l <= r) {
			m = l + r >> 1;
			res = 0;
			for (int it: pos[i]) {
				get(it, root[m]);
			}
			if (res >= 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(int&, int, 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:49:16: note: in expansion of macro 'ls'
   49 |  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:50:16: note: in expansion of macro 'rs'
   50 |  build(t[v].r, rs);
      |                ^~
met.cpp: In function 'void upd(int, int, int, int&, int, int)':
met.cpp:13:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
met.cpp:59:13: note: in expansion of macro 'tm'
   59 |  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:61:35: note: in expansion of macro 'ls'
   61 |   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:64:35: note: in expansion of macro 'rs'
   64 |   upd(pos, val, t[v1].r, t[v2].r, rs);
      |                                   ^~
met.cpp: In function 'void get(int, int, int, 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:17: note: in expansion of macro 'ls'
   78 |  get(r, 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:79:17: note: in expansion of macro 'rs'
   79 |  get(r, t[v].r, rs);
      |                 ^~
met.cpp: In function 'void GazizMadi()':
met.cpp:115:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  115 |    m = l + r >> 1;
      |        ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13916 KB Output is correct
2 Correct 4 ms 13916 KB Output is correct
3 Correct 4 ms 13916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 13916 KB Output is correct
2 Correct 3 ms 13916 KB Output is correct
3 Correct 4 ms 13916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 29020 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 29252 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 30040 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 29008 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 59 ms 35636 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 35280 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -