# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1042959 |
2024-08-03T15:41:41 Z |
armashka |
Meteors (POI11_met) |
C++17 |
|
4286 ms |
65536 KB |
#include<bits/stdc++.h>
#include <unordered_map>
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file(s) freopen(s".in", "r", stdin);freopen(s".out", "w", stdout);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ft first
#define sd second
#define ll long long
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
const int N = 3e5 + 10;
const int M = 1e6 + 5;
const int B = 316;
const ll msize = 2;
const ll mod1 = 1e9 + 7;
const ll mod2 = 998244353;
const long double Phi = acos(-1);
const long long inf = 2e9;
const vector <pair<int, int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
ll binmul(ll x, ll ti, ll m);
ll binpow(ll x, ll ti, ll m);
struct meteor {
ll l, r, x;
} a[N];
struct Government {
ll l, r, ans, id, need;
};
ll n, m, k;
ll t[N * 4], fl[N * 4];
vector <ll> gov[N];
void push(ll v, ll tl, ll tr) {
t[v] += fl[v] * (tr - tl + 1);
t[v] = min(t[v], inf);
if (tl < tr) {
fl[v + v] += fl[v];
fl[v + v] = min(fl[v + v], inf);
fl[v + v + 1] += fl[v];
fl[v + v + 1] = min(fl[v + v + 1], inf);
}
fl[v] = 0;
}
void upd(ll l, ll r, ll x, ll v = 1, ll tl = 1, ll tr = m) {
push(v, tl, tr);
if (r < tl || tr < l) return;
if (l <= tl && tr <= r) {
fl[v] += x;
fl[v] = min(fl[v], inf);
push(v, tl, tr);
return;
}
ll tm = (tl + tr) / 2;
upd(l, r, x, v + v, tl, tm);
upd(l, r, x, v + v + 1, tm + 1, tr);
}
ll get(ll pos, ll v = 1, ll tl = 1, ll tr = m) {
push(v, tl, tr);
if (tl == tr) return t[v];
int tm = (tl + tr) / 2;
if (pos <= tm) return get(pos, v + v, tl, tm);
else return get(pos, v + v + 1, tm + 1, tr);
}
const void solve() {
cin >> n >> m;
for (ll i = 1; i <= m; ++ i) {
int id; cin >> id;
gov[id].pb(i);
}
vector <Government> p;
p.pb({0, 0, 0, 0});
for (ll i = 1; i <= n; ++ i) {
ll x; cin >> x;
p.pb({0, 0, -1, i, x});
}
cin >> k;
for (ll i = 1; i <= k; ++ i) {
cin >> a[i].l >> a[i].r >> a[i].x;
}
for (ll i = 1; i <= n; ++ i) p[i].l = 1, p[i].r = k;
for (ll i = 1; i <= 20; ++ i) {
vector <ll> g[k + 1];
for (ll j = 1; j <= m * 4; ++ j) t[j] = fl[j] = 0;
for (ll j = 1; j <= n; ++ j) {
int mid = (p[j].l + p[j].r) / 2;
g[mid].pb(p[j].id);
}
for (ll j = 1; j <= k; ++ j) {
if (a[j].l <= a[j].r) {
upd(a[j].l, a[j].r, a[j].x);
} else {
upd(a[j].l, m, a[j].x);
upd(1, a[j].r, a[j].x);
}
for (auto id : g[j]) {
ll sum = 0;
for (auto location : gov[id]) {
sum += get(location);
sum = min(sum, inf);
}
ll mid = (p[id].l + p[id].r) / 2;
if (sum >= p[id].need) {
p[id].r = mid - 1;
p[id].ans = mid;
} else {
p[id].l = mid + 1;
}
}
}
}
for (ll i = 1; i <= n; ++ i) {
if (p[i].ans == -1) cout << "NIE\n";
else cout << p[i].ans << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
srand(time(NULL));
// file("promote");
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tt = 1;
// cin >> tt;
for (int i = 1; i <= tt; ++ i) {
// cout << "Caso #" << i << "\n";
solve();
}
#ifndef ONLINE_JUDGE
cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
// Template functions
ll binmul(ll x, ll ti, ll m) { ll res = 0;while (ti){if(ti & 1)res += x;x += x;ti >>= 1; x %= m; res %= m;} return res;}
ll binpow(ll x, ll ti, ll m) { ll res = 1;while (ti){if(ti & 1)(res *= x)%=m;(x*=x)%=m;ti >>= 1; x %= m; res %= m;} return res;}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
12888 KB |
Output is correct |
2 |
Correct |
6 ms |
12892 KB |
Output is correct |
3 |
Correct |
7 ms |
12888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
12892 KB |
Output is correct |
2 |
Correct |
7 ms |
12892 KB |
Output is correct |
3 |
Correct |
7 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
385 ms |
21144 KB |
Output is correct |
2 |
Correct |
452 ms |
22480 KB |
Output is correct |
3 |
Correct |
428 ms |
21832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
21508 KB |
Output is correct |
2 |
Correct |
434 ms |
21540 KB |
Output is correct |
3 |
Correct |
487 ms |
22588 KB |
Output is correct |
4 |
Correct |
118 ms |
18776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
221 ms |
21284 KB |
Output is correct |
2 |
Correct |
352 ms |
22484 KB |
Output is correct |
3 |
Correct |
179 ms |
16220 KB |
Output is correct |
4 |
Correct |
429 ms |
22212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
433 ms |
20804 KB |
Output is correct |
2 |
Correct |
412 ms |
21484 KB |
Output is correct |
3 |
Correct |
410 ms |
21024 KB |
Output is correct |
4 |
Correct |
480 ms |
22720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3457 ms |
52076 KB |
Output is correct |
2 |
Correct |
2246 ms |
42856 KB |
Output is correct |
3 |
Correct |
880 ms |
26244 KB |
Output is correct |
4 |
Correct |
4286 ms |
65536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3374 ms |
51936 KB |
Output is correct |
2 |
Correct |
1467 ms |
42840 KB |
Output is correct |
3 |
Correct |
742 ms |
25172 KB |
Output is correct |
4 |
Correct |
4040 ms |
65536 KB |
Output is correct |