답안 #869615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869615 2023-11-05T04:05:28 Z abhidot Meteors (POI11_met) C++17
61 / 100
6000 ms 28700 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
// #define int long long
#define ll long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define mod2 998244353
#define lld long double
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define V vector
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
using namespace std;
using namespace __gnu_pbds; 
template <typename num_t> using ordered_set = tree<num_t, null_type, less<num_t>, rb_tree_tag, tree_order_statistics_node_update>;
const long long N=200005, INF=2000000000000000000, inf = 2e9+5;
 
int power(int a, int b, int p){
	if(a==0)
	return 0;
	int res=1;
	a%=p;
	while(b>0)
	{
		if(b&1)
		res=(res*a)%p;
		b>>=1;
		a=(a*a)%p;
	}
	return res;
}
 
 
void print(bool n){
    if(n){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
}

int n, m, q, till=0;
vector<int> owners, reqd, ans, pr; 
vector<vector<int>> queries;

void apply(int l, int r, int a){
	if(l<=r){
		pr[l]+=a;
		pr[r+1]-=a;
	}else{
		pr[l]+=a;
		pr[m]-=a;
		pr[0]+=a;
		pr[r+1]-=a;
	}
}

void remove(int l, int r, int a){
	if(l<=r){
		pr[l]-=a;
		pr[r+1]+=a;
	}else{
		pr[l]-=a;
		pr[m]+=a;
		pr[0]-=a;
		pr[r+1]+=a;
	}
}

void update(int idx){
	while(till<idx){
		till++;
		// cout<<q<<" "<<till<<": ";
		// for(int i: queries[till]) cout<<i<<" "; cout<<"\n";
		apply(queries[till][0], queries[till][1], queries[till][2]);
	}
	while(till>idx){
		remove(queries[till][0], queries[till][1], queries[till][2]);
		till--;
	}
}

void rec(int l, int r, vector<int>& states){
	if(l==r){
		for(int i:states) ans[i]=l;
		states.clear();
		return;
	}
	int mid = (l+r)/2;
	update(mid);
	vector<int> have(n);
	int sm=0;
	// cout<<mid<<": \n";
	for(int i=0;i<m;i++){
		sm+=pr[i];
		// cout<<sm<<" ";
		have[owners[i]]+=sm;
	}
	// cout<<"\n";
	vector<int> L, R;
	for(int i:states){
		// cout<<i<<" "<<have[i]<<"\n";
		if(have[i]>=reqd[i]) L.pb(i);
		else R.pb(i);
	}
	states.clear();
	rec(l, mid, L);
	rec(mid+1, r, R);
}
 
int32_t main()
{
    IOS;
		cin>>n>>m;
		owners.resize(m);
		reqd.resize(n);
		ans.resize(n, -1);
		pr.resize(m+1);
		for(int i=0;i<m;i++){
			cin>>owners[i];
			owners[i]--;
		}
		for(int i=0;i<n;i++){
			cin>>reqd[i];
		}
		
		cin>>q;
		queries.resize(q+2);
		queries[0]={0,0,0};
		queries[q+1]={0,0,0};
		for(int i=1;i<=q;i++){
			int l, r, a;
			cin>>l>>r>>a;
			--l, --r;
			queries[i]={l, r, a};
		}
		
		vector<int> states;
		for(int i=0;i<n;i++) states.pb(i);
		rec(0, q+1, states);
		
		for(int i=0;i<n;i++){
			if(ans[i]==q+1){
				cout<<"NIE\n";
			}else cout<<ans[i]<<"\n";
		}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5218 ms 4640 KB Output is correct
2 Correct 2757 ms 7196 KB Output is correct
3 Correct 2316 ms 4724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1882 ms 4432 KB Output is correct
2 Correct 1919 ms 4576 KB Output is correct
3 Correct 3053 ms 6420 KB Output is correct
4 Correct 223 ms 2964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1869 ms 4376 KB Output is correct
2 Correct 2497 ms 6848 KB Output is correct
3 Correct 29 ms 3164 KB Output is correct
4 Correct 2303 ms 5168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2728 ms 3920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6103 ms 28700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6028 ms 27492 KB Time limit exceeded
2 Halted 0 ms 0 KB -