답안 #761883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761883 2023-06-20T10:56:00 Z Baizho Meteors (POI11_met) C++14
39 / 100
3165 ms 42024 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], sum2[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]] = inf;
		pos[o[i]].pb(i);
	}
	for(int i = 1; i<=n; i++) {
		cin>>p[i];
		origp[i] = p[i];
	}
	cin>>k;
	for(ll 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<=n; j++) {
				sum2[j] = sum[j];
			}
			for(ll j = 1; j<=m; j++) {
				scan[j] += scan[j - 1];
//				cout<<i<<" "<<sum[o[j]]<<" "<<o[j]<<" "<<p[o[j]]<<" "<<scan[j]<<" yOLO \n";
				sum[o[j]] += scan[j];
				if(sum[o[j]] >= p[o[j]] && ansblock[o[j]] == inf) {
					ansblock[o[j]] = (i + B - 1) / B;
					vec.pb(o[j]);
				}
			}
			
			for(auto x : vec) {
				ll start = max(1ll, ansblock[x] * B - B + 1), final = i;
//				cout<<x<<" "<<start<<" "<<final<<"\n";
				for(ll h = start; h <= final; h++) {
					ll L, R;
					if(ql[h] > qr[h]) {
						L = ql[h], R = m;
						ll extra = 0;
						ll cnt = upper_bound(all(pos[x]), R) - pos[x].begin() - (lower_bound(all(pos[x]), L) - pos[x].begin());
						extra += 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());
						extra += cnt * qa[h];
						sum2[x] += extra;
						if(sum2[x] >= p[x]) {
							ans[x] = min(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());
						sum2[x] += cnt * qa[h];
						if(sum2[x] >= p[x]) {
							ans[x] = min(ans[x], h);
						} 
					}
				}
			}
			for(ll j = 0; j<=m + 1; j++) {
				scan[j] = 0;
			}
		}
	}
	for(ll i = 1; i<=n; i++) {
		if(ans[i] == inf) 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 Incorrect 6 ms 9776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 9812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 12420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 12816 KB Output is correct
2 Correct 130 ms 13368 KB Output is correct
3 Incorrect 231 ms 14516 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 12596 KB Output is correct
2 Correct 110 ms 14264 KB Output is correct
3 Correct 16 ms 11432 KB Output is correct
4 Correct 120 ms 13916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 12232 KB Output is correct
2 Incorrect 95 ms 13400 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1778 ms 32592 KB Output is correct
2 Correct 678 ms 24720 KB Output is correct
3 Correct 46 ms 16332 KB Output is correct
4 Correct 2980 ms 39532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1687 ms 31388 KB Output is correct
2 Correct 676 ms 24800 KB Output is correct
3 Correct 45 ms 15052 KB Output is correct
4 Correct 3165 ms 42024 KB Output is correct