제출 #1148309

#제출 시각아이디문제언어결과실행 시간메모리
1148309KluydQ새로운 문제 (POI11_met)C++20
74 / 100
1997 ms53280 KiB
#include <bits/stdc++.h>
 
#define respagold ios_base::sync_with_stdio(0), cin.tie(0);
#define ll long long
#define int long long
#define int2 __int128_t
#define FOR( i, x, n, d ) for( int i = x; i <= n; i += d )
#define FORR( i, x, n, d ) for( int i = x; i >= n; i -= d )
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define pb push_back
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define pii pair <int, int>
#define mkp make_pair
 
using namespace std;
 
const int N = 3e5 + 123;
const int inf = 2e18;
const int MOD1 = 1e9 + 7;
const int MOD = 998244353;
const int P = 6547;
 
int a[N], b[N], n, m, k, l[N], r[N], L[N], R[N], x, y, z, w[N], ans[N];
string s; vector <int> v[N], who[N];
 
mt19937 rng( chrono::steady_clock::now().time_since_epoch().count());
 
int rand( int l, int r )
{
    uniform_int_distribution <int> uid( l, r );
    return uid( rng );
}
int t[4 * N];
 
void update( int l, int r, int val )
{
    r ++, l += m, r += m;
    
    while(l < r) 
	{
        if( l & 1 ) t[l ++] += val;
        if( r & 1 ) t[-- r] += val;
        l >>= 1;
        r >>= 1;
    }
}
int get( int pos )
{
    pos += m;
    int res = 0;
    
    while( pos > 0 )
	{
        res += t[pos];
        pos >>= 1;
    }
    return res;
}
void solve()
{
	cin >> n >> m;
	
	FOR( i, 1, m, 1 ) cin >> a[i], who[a[i]].pb(i);
	FOR( i, 1, n, 1 ) cin >> b[i];
	
	cin >> k;
	
	FOR( i, 1, k, 1 ) cin >> l[i] >> r[i] >> w[i];
	FOR( i, 1, n, 1 ) L[i] = 1, R[i] = k, ans[i] = 0;
	
	while(1)
	{
		bool ok = 0;
		
		FOR( i, 1, n, 1 )
		{
			if( L[i] <= R[i] )
			{
				v[(L[i] + R[i]) / 2].pb(i);
				ok = 1;
			}
		}
		if( !ok ) break;
		
		FOR( i, 1, k, 1 )
		{
			if( l[i] > r[i] ) update( l[i], m, w[i] ), update( 1, r[i], w[i] );
			else update( l[i], r[i], w[i] );
			
			for( auto x : v[i] )
			{
				int bobik = 0;
				for( auto wh : who[x] ) bobik += get(wh);
				if( bobik >= b[x] ) R[x] = i - 1, ans[x] = i;
				else L[x] = i + 1;
			}
			v[i].clear();
		}
		FOR( i, 1, k, 1 )
		{
			if( l[i] > r[i] ) update( l[i], m, -w[i] ), update( 1, r[i], -w[i] );
			else update( l[i], r[i], -w[i] );
		}
	}
	FOR( i, 1, n, 1 )
	{
		if( ans[i] == 0 ) cout << "NIE\n";
		else cout << ans[i] << '\n';
	}
}
signed main() 
{
//	freopen("connect.in", "r", stdin);
//	freopen("connect.out", "w", stdout);
	    
    respagold
    
    int test = 1;
    
    if( !test ) cin >> test;
	
	while( test -- )
	{
		solve();
	}
}
// solved by KluydQ  
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...