# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
761614 |
2023-06-20T05:34:10 Z |
vjudge1 |
Meteors (POI11_met) |
C++17 |
|
2313 ms |
37412 KB |
#include "bits/stdc++.h"
using namespace std;
// #define ORD_SET
// #define ROPE
#ifdef ORD_SET
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif
#ifdef ROPE
#include <ext/rope>
using namespace __gnu_cxx;
#endif
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void ioigold2024insh() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
void pre(ll a) { cout<<fixed<<setprecision(a); }
ll bit(ll a) { return __builtin_popcountll(a); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }
struct sn { ll l, r, x; };
const ll mod = 1e9+7, inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN;
const ll N = 3e5+5;
ll a[N], b[N], l[N], r[N], x[N], d[N], sum[N], t[N], upd[N], B = 547;
vector<ll> gr[600], g[N];
void kigash() {
ll n, m;
cin>>m>>n;
for(ll i=1; i<=n; i++) cin>>a[i], g[a[i]].pb(i);
for(ll i=1; i<=m; i++) cin>>b[i], t[i] = -1;
ll q;
cin>>q, B = min(B, q);
for(ll i=1; i<=q; i++) {
cin>>l[i]>>r[i]>>x[i];
if(l[i]>r[i]) d[1] += x[i], d[r[i]+1] -= x[i], d[l[i]] += x[i], d[n+1] -= x[i];
else d[l[i]] += x[i], d[r[i]+1] -= x[i];
if(i%B==0 || i==q) {
for(ll j=1; j<=n; j++) d[j] += d[j-1];
for(ll j=1; j<=m; j++) sum[j] = 0;
for(ll j=1; j<=n; j++) sum[a[j]] += d[j];
for(ll j=1; j<=m; j++) {
if(sum[j]>=b[j] && t[j]==-1) t[j] = (i-1)/B, gr[(i-1)/B].pb(j);
}
for(ll j=n; j>=1; j--) d[j] -= d[j-1];
}
}
for(ll i=0; i<=n; i++) d[i] = 0;
for(ll i=0; i<=m; i++) sum[i] = 0;
for(ll i=1; i<=q; i++) {
for(auto num: gr[(i-1)/B]) {
if(upd[num]) continue;
if(g[num].empty()) continue;
if(l[i]>r[i]) {
ll R = upper_bound(all(g[num]), r[i])-g[num].begin()-1;
sum[num] += (R+1)*x[i];
ll L = lower_bound(all(g[num]), l[i])-g[num].begin();
sum[num] += (sz(g[num])-L)*x[i];
}
else {
ll L = lower_bound(all(g[num]), l[i])-g[num].begin();
if(L==sz(g[num])) continue;
ll R = upper_bound(all(g[num]), r[i])-g[num].begin()-1;
if(R==-1) continue;
sum[num] += (R-L+1)*x[i];
}
if(sum[num]>=b[num]) t[num] = i, upd[num] = 1;
}
if(l[i]>r[i]) d[1] += x[i], d[r[i]+1] -= x[i], d[l[i]] += x[i], d[n+1] -= x[i];
else d[l[i]] += x[i], d[r[i]+1] -= x[i];
if(i%B==0) {
for(ll j=1; j<=n; j++) d[j] += d[j-1];
for(ll j=1; j<=m; j++) sum[j] = 0;
for(ll j=1; j<=n; j++) sum[a[j]] += d[j];
for(ll j=n; j>=1; j--) d[j] -= d[j-1];
}
}
for(ll i=1; i<=q; i++) {
if(t[i]==-1) cout<<"NIE\n";
else cout<<t[i]<<"\n";
}
return;
}
signed main(/*Kigash Amir*/) {
// freopen("");
ioigold2024insh();
ll tt = 1;
// cin>>tt;
for(ll i=1; i<=tt; i++) kigash();
exit(0);
}
Compilation message
met.cpp: In function 'void freopen(std::string)':
met.cpp:31:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:31:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
63 ms |
10136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
91 ms |
10480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
62 ms |
10372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
61 ms |
9936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2074 ms |
37412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2313 ms |
36452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |