# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
761812 |
2023-06-20T09:59:38 Z |
vjudge1 |
Meteors (POI11_met) |
C++17 |
|
2432 ms |
24028 KB |
#include <bits/stdc++.h>
using namespace std;
// #pragma comment(linker, "/stack:2000000000")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,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 int MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const int N = ll(3e5)+10;
const long long inf = 9e18;
const long double eps = 1e-15L;
const int B = 400;
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], p[N], k, scan[N], ansblock[N], ans[N], origp[N], ql[N], qr[N], qa[N];
vector<int>pos[N];
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>>p[i];
origp[i] = p[i];
}
cin>>k;
for(int i = 1; i<=k; i++) {
int l, r, a;
cin>>l>>r>>a;
ql[i] = l;
qr[i] = r;
qa[i] = a;
if(l > r) {
scan[l] += a;
scan[m + 1] -= a;
scan[1] += a;
scan[r + 1] -= a;
}
else {
scan[l] += a;
scan[r + 1] -= a;
}
if(i == k || i % B == 0) {
vector<int> vec;
for(int j = 1; j<=m; j++) {
scan[j] += scan[j - 1];
p[o[j]] -= scan[j];
if(p[o[j]] <= 0 && ansblock[o[j]] == 0) {
ansblock[o[j]] = (i + B - 1) / B;
vec.pb(o[j]);
}
}
for(auto x : vec) {
int start = max(1, i - B + 1), final = i;
for(int h = start; h <= final; h++) {
int L, R;
if(ql[h] > qr[h]) {
L = ql[h], R = m;
int cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
origp[x] -= cnt * qa[h];
if(origp[x] <= 0 && ans[x] == 0) {
ans[x] = h;
break;
}
L = 1, R = qr[h];
cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
origp[x] -= cnt * qa[h];
if(origp[x] <= 0 && ans[x] == 0) {
ans[x] = h;
break;
}
}
else {
L = ql[h], R = qr[h];
int cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
origp[x] -= cnt * qa[h];
if(origp[x] <= 0 && ans[x] == 0) {
ans[x] = h;
break;
}
}
}
}
for(int j = 1; j<=m; j++) {
scan[j] = 0;
origp[o[j]] = p[o[j]];
}
}
}
for(int i = 1; i<=n; i++) {
if(ans[i] == 0) cout<<"NIE\n";
else cout<<ans[i]<<"\n";
}
}
int main() {
// Freopen("guard");
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
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:30:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:30:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | 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 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
3 ms |
7444 KB |
Output is correct |
3 |
Incorrect |
5 ms |
7460 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
8656 KB |
Output is correct |
2 |
Correct |
43 ms |
9332 KB |
Output is correct |
3 |
Correct |
101 ms |
9120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8908 KB |
Output is correct |
2 |
Correct |
85 ms |
8940 KB |
Output is correct |
3 |
Correct |
73 ms |
9576 KB |
Output is correct |
4 |
Incorrect |
23 ms |
8660 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
8768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
8672 KB |
Output is correct |
2 |
Correct |
79 ms |
8892 KB |
Output is correct |
3 |
Correct |
49 ms |
8728 KB |
Output is correct |
4 |
Correct |
113 ms |
9760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1618 ms |
19340 KB |
Output is correct |
2 |
Correct |
862 ms |
14648 KB |
Output is correct |
3 |
Correct |
42 ms |
10560 KB |
Output is correct |
4 |
Correct |
2432 ms |
24028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1501 ms |
18712 KB |
Output is correct |
2 |
Correct |
838 ms |
14692 KB |
Output is correct |
3 |
Incorrect |
40 ms |
9804 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |