답안 #761940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761940 2023-06-20T12:20:29 Z Baizho Meteors (POI11_met) C++17
100 / 100
3877 ms 37784 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];
		pos[o[i]].pb(i);
	}
	for(int i = 1; i<=n; i++) {
		cin>>p[i];
		ans[i] = ansblock[i] = -1;
	}
	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) continue;
				if(p[j] <= sum[j] && ansblock[j] == -1) {
					vec.pb(j);
					ansblock[j] = (i + B - 1) / B;
				}
			}
			for(ll j = 1; j<=n; j++) sum[j] = 0;
			ll thisblock = (i + B - 1) / B;
			ll start = max(1ll, thisblock * B - B + 1), final = i;
			for(ll j = start; j <= final; j++) {
				for(auto x : vec) {
					ll L, R;
					if(ql[j] > qr[j]) {
						L = ql[j], 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[j];
						
						L = 1, R = qr[j];
						cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
						
						sum[x] += cnt * qa[j];
						if(p[x] <= sum[x] && ans[x] == -1) {
							ans[x] = j;
						}
						
 					}
 					else {
 						L = ql[j], R = qr[j];
						ll cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
						sum[x] += cnt * qa[j];
						if(p[x] <= sum[x] && ans[x] == -1) {
							ans[x] = j;
						}
					}
				}
			}
			for(ll j = 1; j<=m; j++) {
				p[o[j]] -= scan[j];
				scan[j] = 0;
			}
			scan[0] = scan[m + 1] = 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(); }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9768 KB Output is correct
2 Correct 5 ms 9868 KB Output is correct
3 Correct 7 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9812 KB Output is correct
2 Correct 8 ms 9868 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 12424 KB Output is correct
2 Correct 55 ms 14020 KB Output is correct
3 Correct 191 ms 13488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 12724 KB Output is correct
2 Correct 118 ms 12748 KB Output is correct
3 Correct 314 ms 13536 KB Output is correct
4 Correct 44 ms 12432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 12580 KB Output is correct
2 Correct 107 ms 13296 KB Output is correct
3 Correct 15 ms 10964 KB Output is correct
4 Correct 126 ms 13076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 12144 KB Output is correct
2 Correct 112 ms 12696 KB Output is correct
3 Correct 63 ms 12876 KB Output is correct
4 Correct 172 ms 14008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2667 ms 31032 KB Output is correct
2 Correct 1608 ms 23980 KB Output is correct
3 Correct 45 ms 15568 KB Output is correct
4 Correct 3877 ms 35748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2500 ms 30004 KB Output is correct
2 Correct 1595 ms 24108 KB Output is correct
3 Correct 44 ms 14412 KB Output is correct
4 Correct 3574 ms 37784 KB Output is correct