Submission #381220

# Submission time Handle Problem Language Result Execution time Memory
381220 2021-03-24T19:00:35 Z aryan12 Meteors (POI11_met) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#pragma GCC optimize "trapv"
 
using namespace std;
 
vector<long long> req;
vector<vector<long long>> land;
vector<array<long long, 3>> D;
vector<long long> ans;
 
long long n, m;
 
struct BIT{
	vector<long long> tree;
	long long n;
 
	void init(long long _n){
		n = _n;
		tree.resize(n+1);
	}
 
	void upd(long long idx, long long val){
		for(; idx <= n; idx += (idx&(-idx)))
			tree[idx] += val;
	}
 
	void upd(long long l, long long r, long long val){
		upd(l, val);
		upd(r+1, -val);
	}
 
	long long query(long long idx){
		long long sum = 0;
		for(; idx > 0; idx -= (idx&(-idx)))
			sum += tree[idx];
		return sum;
	}
 
}bit;
 
void PBS(long long l, long long r, vector<long long> active){
	if(active.size() == 0)
		return;
 
	if(r - l == 1){
		for(long long i : active)
			ans[i] = l;
		return;
	}
 
	long long mid = (l + r) >> 1;
	
	for(long long i = l; i < mid; i++){
		if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], long long(D[i][2]));
		else{
			bit.upd(D[i][0], m, long long(D[i][2]));
			bit.upd(1, D[i][1], long long(D[i][2]));
		}
	}
	
	vector<long long> nq[2];
	
	for(long long i : active){
		long long sum = 0;
		for(long long v : land[i]) sum += bit.query(v);
		if(sum >= req[i]) nq[0].push_back(i);
		else{
			req[i] -= sum;
			nq[1].push_back(i);
		}
	}
 
	for(long long i = l; i < mid; i++){
		if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], long long(-D[i][2]));
		else{
			bit.upd(D[i][0], m, long long(-D[i][2]));
			bit.upd(1, D[i][1], long long(-D[i][2]));
		}
	}
 
	PBS(l, mid, nq[0]);
	PBS(mid, r, nq[1]);
}
 
int32_t main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
 
	cin >> n >> m;
	land.resize(n+1), req.resize(n+1);
	ans.resize(n+1);
 
	bit.init(m);
 
	for(long long i = 1; i <= m; i++){
		long long x;
		cin >> x;
		land[x].push_back(i);
	}
 
	for(long long i = 1; i <= n; i++)
		cin >> req[i];
 
	long long k;
	cin >> k;
 
	D.resize(k+1);
	for(long long i = 1; i <= k; i++){
		auto& [l, r, upd] = D[i];
		cin >> l >> r >> upd;
	}
 
	vector<long long> cur(n);
	iota(cur.begin(), cur.end(), 1);
	PBS(1, k+2, cur);
 
	for(long long i = 1; i <= n; i++)
		if(ans[i] == k+1) cout << "NIE\n";
		else cout << ans[i] << '\n';
 
	return 0; 
}

Compilation message

met.cpp: In function 'void PBS(long long int, long long int, std::vector<long long int>)':
met.cpp:54:52: error: expected primary-expression before 'long'
   54 |   if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], long long(D[i][2]));
      |                                                    ^~~~
met.cpp:56:24: error: expected primary-expression before 'long'
   56 |    bit.upd(D[i][0], m, long long(D[i][2]));
      |                        ^~~~
met.cpp:57:24: error: expected primary-expression before 'long'
   57 |    bit.upd(1, D[i][1], long long(D[i][2]));
      |                        ^~~~
met.cpp:74:52: error: expected primary-expression before 'long'
   74 |   if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], long long(-D[i][2]));
      |                                                    ^~~~
met.cpp:76:24: error: expected primary-expression before 'long'
   76 |    bit.upd(D[i][0], m, long long(-D[i][2]));
      |                        ^~~~
met.cpp:77:24: error: expected primary-expression before 'long'
   77 |    bit.upd(1, D[i][1], long long(-D[i][2]));
      |                        ^~~~