답안 #381219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381219 2021-03-24T18:59:10 Z aryan12 Meteors (POI11_met) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#pragma GCC optimize "trapv"
#define int64_t long long
 
using namespace std;
 
vector<int64_t> req;
vector<vector<int64_t>> land;
vector<array<int64_t, 3>> D;
vector<int64_t> ans;
 
int64_t n, m;
 
struct BIT{
	vector<int64_t> tree;
	int64_t n;
 
	void init(int64_t _n){
		n = _n;
		tree.resize(n+1);
	}
 
	void upd(int64_t idx, int64_t val){
		for(; idx <= n; idx += (idx&(-idx)))
			tree[idx] += val;
	}
 
	void upd(int64_t l, int64_t r, int64_t val){
		upd(l, val);
		upd(r+1, -val);
	}
 
	int64_t query(int64_t idx){
		int64_t sum = 0;
		for(; idx > 0; idx -= (idx&(-idx)))
			sum += tree[idx];
		return sum;
	}
 
}bit;
 
void PBS(int64_t l, int64_t r, vector<int64_t> active){
	if(active.size() == 0)
		return;
 
	if(r - l == 1){
		for(int64_t i : active)
			ans[i] = l;
		return;
	}
 
	int64_t mid = (l + r) >> 1;
	
	for(int64_t i = l; i < mid; i++){
		if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], int64_t(D[i][2]));
		else{
			bit.upd(D[i][0], m, int64_t(D[i][2]));
			bit.upd(1, D[i][1], int64_t(D[i][2]));
		}
	}
	
	vector<int64_t> nq[2];
	
	for(int64_t i : active){
		int64_t sum = 0;
		for(int64_t 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(int64_t i = l; i < mid; i++){
		if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], int64_t(-D[i][2]));
		else{
			bit.upd(D[i][0], m, int64_t(-D[i][2]));
			bit.upd(1, D[i][1], int64_t(-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(int64_t i = 1; i <= m; i++){
		int64_t x;
		cin >> x;
		land[x].push_back(i);
	}
 
	for(int64_t i = 1; i <= n; i++)
		cin >> req[i];
 
	int64_t k;
	cin >> k;
 
	D.resize(k+1);
	for(int64_t i = 1; i <= k; i++){
		auto& [l, r, upd] = D[i];
		cin >> l >> r >> upd;
	}
 
	vector<int64_t> cur(n);
	iota(cur.begin(), cur.end(), 1);
	PBS(1, k+2, cur);
 
	for(int64_t 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:3:17: error: expected primary-expression before 'long'
    3 | #define int64_t long long
      |                 ^~~~
met.cpp:55:52: note: in expansion of macro 'int64_t'
   55 |   if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], int64_t(D[i][2]));
      |                                                    ^~~~~~~
met.cpp:3:17: error: expected primary-expression before 'long'
    3 | #define int64_t long long
      |                 ^~~~
met.cpp:57:24: note: in expansion of macro 'int64_t'
   57 |    bit.upd(D[i][0], m, int64_t(D[i][2]));
      |                        ^~~~~~~
met.cpp:3:17: error: expected primary-expression before 'long'
    3 | #define int64_t long long
      |                 ^~~~
met.cpp:58:24: note: in expansion of macro 'int64_t'
   58 |    bit.upd(1, D[i][1], int64_t(D[i][2]));
      |                        ^~~~~~~
met.cpp:3:17: error: expected primary-expression before 'long'
    3 | #define int64_t long long
      |                 ^~~~
met.cpp:75:52: note: in expansion of macro 'int64_t'
   75 |   if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], int64_t(-D[i][2]));
      |                                                    ^~~~~~~
met.cpp:3:17: error: expected primary-expression before 'long'
    3 | #define int64_t long long
      |                 ^~~~
met.cpp:77:24: note: in expansion of macro 'int64_t'
   77 |    bit.upd(D[i][0], m, int64_t(-D[i][2]));
      |                        ^~~~~~~
met.cpp:3:17: error: expected primary-expression before 'long'
    3 | #define int64_t long long
      |                 ^~~~
met.cpp:78:24: note: in expansion of macro 'int64_t'
   78 |    bit.upd(1, D[i][1], int64_t(-D[i][2]));
      |                        ^~~~~~~