# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
893933 |
2023-12-27T17:22:59 Z |
vjudge1 |
Meteors (POI11_met) |
C++17 |
|
890 ms |
65536 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")
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(5e5)+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); }
ll n, m, o[N], need[N], k, ql[N], qr[N], qa[N], bl[N], br[N];
vector<int> check[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;
}
int 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(int i = 1; i <= m; i ++) {
cin>>o[i];
pos[o[i]].pb(i);
}
for(int i = 1; i <= n; i ++) cin>>need[i];
cin>>k;
for(int i = 1; i <= k; i ++) cin>>ql[i]>>qr[i]>>qa[i];
for(int i = 1; i <= n; i ++) {
bl[i] = 1, br[i] = k + 1;
}
for(int bin = 0; bin <= 30; bin ++) {
bool ok = 0;
for(int i = 1; i <= n; i ++) {
if(bl[i] < br[i]) {
check[(bl[i] + br[i]) / 2].pb(i);
ok = 1;
}
}
if(!ok) break;
for(int i = 1; i <= k; i ++) {
if(ql[i] > qr[i]) {
upd(1, qr[i], qa[i]);
upd(ql[i], m, qa[i]);
} else {
upd(ql[i], qr[i], 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";
res += get(p, p);
if(res >= need[j]) break;
}
// cout<<res<<"\n";
if(need[j] <= res) br[j] = i;
else bl[j] = i + 1;
}
check[i].clear();
}
for (int j = 1; j <= m * 4; ++ j) t[j] = 0;
}
for(int i = 1; i <= n; i ++) {
if(bl[i] > k) cout<<"NIE\n";
else cout<<bl[i]<<"\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:35:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:35:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | 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 |
9 ms |
37208 KB |
Output is correct |
2 |
Correct |
11 ms |
37468 KB |
Output is correct |
3 |
Correct |
10 ms |
37212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
37208 KB |
Output is correct |
2 |
Correct |
10 ms |
37460 KB |
Output is correct |
3 |
Correct |
10 ms |
37468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
243 ms |
42308 KB |
Output is correct |
2 |
Correct |
350 ms |
44000 KB |
Output is correct |
3 |
Correct |
358 ms |
43900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
324 ms |
43472 KB |
Output is correct |
2 |
Correct |
323 ms |
43348 KB |
Output is correct |
3 |
Correct |
327 ms |
44100 KB |
Output is correct |
4 |
Correct |
101 ms |
43088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
42720 KB |
Output is correct |
2 |
Correct |
249 ms |
44632 KB |
Output is correct |
3 |
Correct |
125 ms |
37432 KB |
Output is correct |
4 |
Correct |
326 ms |
44112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
282 ms |
39928 KB |
Output is correct |
2 |
Correct |
266 ms |
43344 KB |
Output is correct |
3 |
Correct |
309 ms |
40332 KB |
Output is correct |
4 |
Correct |
345 ms |
45248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
727 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
890 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |