Submission #761919

# Submission time Handle Problem Language Result Execution time Memory
761919 2023-06-20T11:37:30 Z Baizho Meteors (POI11_met) C++17
39 / 100
5194 ms 37844 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(4e5)+10;
const long long inf = 1e18;
//const int inf = 1e9;
const long double eps = 1e-15L;
const ll B = 400;
 
 
ll n, m, o[N], p[N], k, ansblock[N], ans[N], ql[N], qr[N], qa[N], sum[N];
ll scan[N], origp[N];
vector<ll>pos[N];
 
void Baizho() {
	cin>>n>>m;
	for(int i = 1; i<=m; i++) {
		cin>>o[i];
		ans[o[i]] = ansblock[o[i]] = -1;
		pos[o[i]].pb(i);
	}
	for(int i = 1; i<=n; i++) {
		cin>>p[i];
	}
	cin>>k;
	for(int i = 1; i<=k; i++) {
		ll 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<ll> vec;
			for(ll j = 1; j<=m; j++) scan[j] += scan[j - 1];
			for(ll j = 1; j<=n; j++) sum[j] = 0;
			for(ll j = 1; j<=m; j++) sum[o[j]] += scan[j];
			for(ll j = 1; j<=n; j++) {
				if(ans[j] != -1 || ansblock[j] != -1) continue;
				if(p[j] <= sum[j]) {
					vec.pb(j);
					ansblock[j] = (i + B - 1) / B;
				}
			}
			for(ll j = 1; j<=n; j++) sum[j] = 0;
			for(auto x : vec) {
				ll start = max(1ll, ansblock[x] * B - B + 1), final = i;
				for(ll h = start; h <= final; h++) {
					ll L, R;
					if(ql[h] > qr[h]) {
						L = ql[h], R = m;
						ll cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
						sum[x] += cnt * qa[h];
						
						L = 1, R = qr[h];
						cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
						
						sum[x] += cnt * qa[h];
						
						if(p[x] <= sum[x] && ans[x] == -1) {
							ans[x] = h;
						}
						
 					}
 					else {
 						L = ql[h], R = qr[h];
						ll cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
						sum[x] += cnt * qa[h];
						if(p[x] <= sum[x] && ans[x] == -1) {
							ans[x] = h;
						}
					}
				}
				for(ll h = start; h <= final; h++) {
					ll L, R;
					if(ql[h] > qr[h]) {
						L = ql[h], R = m;
						ll cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
						sum[x] -= cnt * qa[h];
						
						L = 1, R = qr[h];
						cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
						
						sum[x] -= cnt * qa[h];
						
						
 					}
 					else {
 						L = ql[h], R = qr[h];
						ll cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
						sum[x] -= cnt * qa[h];
					}
				}
			}
			for(ll j = 1; j<=m; j++) {
				p[o[j]] -= scan[j];
				scan[j] = 0;
			}
			
		}
	}
	for(int i = 1; i<=n; i++) {
		if(ans[i] == -1) 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(); }
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 9812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 9856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 12376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 177 ms 12716 KB Output is correct
2 Correct 202 ms 12712 KB Output is correct
3 Incorrect 410 ms 13568 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 12564 KB Output is correct
2 Correct 142 ms 13312 KB Output is correct
3 Correct 19 ms 10996 KB Output is correct
4 Correct 205 ms 13252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 12232 KB Output is correct
2 Incorrect 155 ms 12676 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3342 ms 31040 KB Output is correct
2 Correct 1621 ms 23988 KB Output is correct
3 Correct 50 ms 15692 KB Output is correct
4 Correct 5194 ms 35760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3190 ms 30020 KB Output is correct
2 Correct 1623 ms 24108 KB Output is correct
3 Correct 48 ms 14412 KB Output is correct
4 Correct 4550 ms 37844 KB Output is correct