# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
761638 |
2023-06-20T06:38:53 Z |
vjudge1 |
Meteors (POI11_met) |
C++17 |
|
5 ms |
1920 KB |
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"
const int maxn = 1e3 + 100;
const ll INF = (ll)2e18;
const int inf = (ll)2e9;
const int maxl = 26;
const int MOD = 1e9 + 7;
ll n, m, q;
vector<ll> g[maxn];
ll a[maxn];
ll l[maxn];
ll r[maxn];
ll c[maxn];
ll d[maxn * 4];
ll used[maxn * 4];
ll ans[maxn];
void clear(ll v = 1, ll tl = 1, ll tr = m){
if(!used[v]) return;
used[v] = 0; d[v] = 0;
if(tl < tr){
ll mid = (tl + tr) >> 1;
clear(v<<1, tl, mid);
clear(v<<1|1, mid+1, tr);
}
}
bool ok(ll l, ll r, ll tl, ll tr){
if(l <= r) return l <= tl && tr <= r;
return l <= tl || tr <= r;
}
bool nt(ll l, ll r, ll tl, ll tr){
if(l <= r) return tr < l || tl > r;
return tr < l && tl > r;
}
void upd(ll l, ll r, ll x, ll v = 1, ll tl = 1, ll tr = m){
if(nt(l, r, tl, tr)) return;
used[v] = 1;
if(ok(l, r, tl, tr)) d[v] += x;
else{
ll mid = (tl + tr) >> 1;
upd(l, r, x, v<<1, tl, mid);
upd(l, r, x, v<<1|1, mid+1, tr);
}
}
ll get(ll i, ll v = 1, ll tl = 1, ll tr = m){
if(tl == tr) return d[v];
ll mid = (tl + tr) >> 1;
if(i <= mid) return get(i, v<<1, tl, mid) + d[v];
else return get(i, v<<1|1, mid + 1, tr) + d[v];
}
void f(vector<ll> &v, ll tl = 1, ll tr = n){
if(tl == tr){
for(ll x: v){
ll sum = 0;
for(ll i: g[x]){
sum += ok(l[tl], r[tl], i, i) * c[tl];
}
if(a[x] > sum) ans[x] = -1;
else ans[x] = tl;
}
} else{
ll mid = (tl + tr) >> 1;
clear();
for(ll i = tl; i <= mid; i++){
upd(l[i], r[i], c[i]);
}
vector<ll> L, R;
for(ll x: v){
ll sum = 0;
for(ll i: g[x]){
sum += get(i);
}
if(sum >= a[x]) L.push_back(x);
else a[x] -= sum, R.push_back(x);
}
f(L, tl, mid);
f(R, mid + 1, tr);
}
}
void test(){
cin >> n >> m;
for(ll i = 1; i <= m; i++){
ll x; cin >> x;
g[x].push_back(i);
}
vector<ll> v;
for(ll i = 1; i <= n; i++){
cin >> a[i];
v.push_back(i);
}
cin >> q;
for(ll i = 1; i <= q; i++){
cin >> l[i] >> r[i] >> c[i];
}
f(v);
for(ll i = 1; i <= n; i++){
if(ans[i] == -1) cout << "NIE\n";
else cout << ans[i] << ent;
}
}
int main(){
// freopen("cows.in", "r", stdin);
// freopen("cows.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t; t = 1;
while(t--) test();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
1920 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
724 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
1616 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |