# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
893948 |
2023-12-27T17:38:44 Z |
Baizho |
Meteors (POI11_met) |
C++14 |
|
3878 ms |
45388 KB |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// #pragma GCC optimize("Ofast,unroll-loops,fast-math")
// #pragma GCC target("popcnt")
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back
const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const int N = ll(3e5)+100;
const long long inf = 2e18;
const long double eps = 1e-15L;
ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; }
ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;}
void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
int n, m, o[N], need[N], k, ql[N], qr[N], qa[N], bl[N], br[N];
vector<int> pos[N];
ll t[N * 4];
ll get(ll l, ll r, ll v = 1, ll tl = 1, ll tr = m) {
if(l <= tl && tr <= r) return t[v];
if(tr < l || r < tl) return 0;
ll tm = (tl + tr) / 2;
return get(l, r, v + v, tl, tm) + get(l, r, v + v + 1, tm + 1, tr) + t[v];
}
void upd(ll l, ll r, ll val, ll v = 1, ll tl = 1, ll tr = m) {
if (tr < l || r < tl) return;
if (l <= tl && tr <= r) {
t[v] += val;
return;
}
ll tm = (tl + tr) / 2;
upd(l, r, val, v + v, tl, tm);
upd(l, r, val, v + v + 1, tm + 1, tr);
}
void Baizho() {
cin>>n>>m;
for(ll i = 1; i <= m; i ++) {
cin>>o[i];
pos[o[i]].pb(i);
}
for(ll i = 1; i <= n; i ++) cin>>need[i];
cin>>k;
for(ll i = 1; i <= k; i ++) cin>>ql[i]>>qr[i]>>qa[i];
for(ll i = 1; i <= n; i ++) {
bl[i] = 1, br[i] = k;
}
for(ll bin = 0; bin <= 20; bin ++) {
vector<int> check[k + 5];
for(ll i = 1; i <= n; i ++) {
if(bl[i] <= br[i]) {
check[(bl[i] + br[i]) / 2].pb(i);
}
}
for(ll i = 1; i <= k; i ++) {
if(ql[i] <= qr[i]) {
upd(ql[i], qr[i], qa[i]);
} else {
upd(1, qr[i], qa[i]);
upd(ql[i], m, qa[i]);
}
for(auto j : check[i]) {
ll res = 0;
// cout<<j<<" "<<i<<"\n";
for(auto p : pos[j]) {
// cout<<p<<" "<<get(p, p)<<"\n";
if(res < need[j]) res += get(p, p);
}
// cout<<res<<"\n";
if(need[j] <= res) br[j] = i - 1;
else bl[j] = i + 1;
}
}
for (ll j = 1; j <= m * 4; ++ j) t[j] = 0;
}
for(ll i = 1; i <= n; i ++) {
if(br[i] + 1 > k) cout<<"NIE\n";
else cout<<br[i] + 1<<"\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
// precalc();
int ttt = 1;
// cin>>ttt;
for(int i=1; i<=ttt; i++) {Baizho(); }
}
Compilation message
met.cpp: In function 'void Freopen(std::string)':
met.cpp:37:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:37:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
14692 KB |
Output is correct |
2 |
Correct |
7 ms |
14684 KB |
Output is correct |
3 |
Correct |
6 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
14684 KB |
Output is correct |
2 |
Correct |
7 ms |
14784 KB |
Output is correct |
3 |
Correct |
7 ms |
14952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
18740 KB |
Output is correct |
2 |
Correct |
383 ms |
19248 KB |
Output is correct |
3 |
Correct |
361 ms |
19044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
19200 KB |
Output is correct |
2 |
Correct |
349 ms |
19020 KB |
Output is correct |
3 |
Correct |
345 ms |
19292 KB |
Output is correct |
4 |
Correct |
93 ms |
18036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
18780 KB |
Output is correct |
2 |
Correct |
195 ms |
19588 KB |
Output is correct |
3 |
Correct |
142 ms |
16220 KB |
Output is correct |
4 |
Correct |
357 ms |
19300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
18772 KB |
Output is correct |
2 |
Correct |
285 ms |
18920 KB |
Output is correct |
3 |
Correct |
351 ms |
18724 KB |
Output is correct |
4 |
Correct |
364 ms |
19660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3270 ms |
36356 KB |
Output is correct |
2 |
Correct |
783 ms |
32720 KB |
Output is correct |
3 |
Correct |
695 ms |
20724 KB |
Output is correct |
4 |
Correct |
3878 ms |
42388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3244 ms |
36072 KB |
Output is correct |
2 |
Correct |
793 ms |
32708 KB |
Output is correct |
3 |
Correct |
600 ms |
19444 KB |
Output is correct |
4 |
Correct |
3720 ms |
45388 KB |
Output is correct |