답안 #501705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501705 2022-01-04T10:46:47 Z Nuraly_Serikbay Meteors (POI11_met) C++14
0 / 100
6000 ms 58268 KB
#pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
  
#define endl "\n"
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz size()
#define rep(i,k,n) for(int i = k ; i <= n ; ++i)
#define per(i,k,n) for(int i = k ; i >= n ; --i)
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define fr(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define toqta return 0
#define PERMUTE next_permutation
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
#define a() a + 1, a + n + 1  
#define int long long
  
using namespace std;

/*
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse,-fgcse-lm")
#pragma GCC optimize("-ftree-pre,-ftree-vrp")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
	#pragma GCC optimize("unroll-loops")
*/

typedef long long ll;
typedef unsigned long long ull;
typedef string S;
typedef double D;
typedef long double lld;
   
const int N = 1e6 + 17;
const int modd = 1e9 + 7;
const ll INF = 1e18 - 19;
const int P = 37;
const ll NN = 1e7 + 17;
const D eps = 1e-19;
const double pi = 3.141592653589793238462643383279 ;   
              

ll n, m;	
ll a[N], q, sum[N];
vector <ll> v[N];
ll mod[N * 4];
ll L[N], R[N], x[N];

void push (int v, int l, int r) {
	if (mod[v] != 0 && v * 2 + 1 < N * 4) {
		mod[v * 2] += mod[v];
		mod[v * 2 + 1] += mod[v];
		mod[v] = 0;
	}
}

void update (ll v, ll tl, ll tr, ll l, ll r, ll val) {
	if (tr < l || r < tl) return;
	if (l <= tl && tr <= r) {
		mod[v] += val;
		push(v, tl, tr);
		return;
	}
	ll mid = (tl + tr) / 2;
	push (v, tl, tr);
	update (v * 2, tl, mid, l, r, val);
	update (v * 2 + 1, mid + 1, tr, l, r, val);
	mod[v] = mod[v * 2] + mod[v * 2 + 1];
	return;
}


ll get (int v, int tl, int tr, int pos) {
	if (tl == tr) {
		return mod[v];
 	}
 	push(v, tl, tr);
 	int mid = (tl + tr) / 2;
 	if (pos <= mid) return get(v * 2, tl, mid, pos);
 	else return get(v * 2 + 1, mid + 1, tr, pos);
}

ll check (ll len, ll pos) {
	ll ans = 0;
	for (int i = 1; i <= len; ++i) {
		if (L[i] > R[i]) {
			update(1, 1, m, L[i], m, x[i]);				
			update(1, 1, m, 1, R[i], x[i]);	
		} else {
			update(1, 1, m, L[i], R[i], x[i]);
		}
	}
	for (int i = 0; i < v[pos].size(); ++i) {
		ans += get(1, 1, m, v[pos][i]);
	}
	for (int i = 1; i <= len; ++i) {
		if (L[i] > R[i]) {
			update(1, 1, m, L[i], m, -x[i]);				
			update(1, 1, m, 1, R[i], -x[i]);	
		} else {
			update(1, 1, m, L[i], R[i], -x[i]);
		}
	}
	return ans;
}

void Solution (/*Nuraly.Serikbay*/) {
	cin >> n >> m;
	vector <int> west;
	for (int i = 1; i <= m; ++ i) {
		cin >> a[i];
		west.pb(a[i]);
	}
	sort(all(west));
	for (int i = 1; i <= m; ++i) {
		a[i] = lower_bound(all(west), a[i]) - west.begin() + 1;
		v[a[i]].pb(i);
	}
	for (int i = 1; i <= n; ++ i) {
		cin >> sum[i];
	}
	cin >> q;
	for (int i = 1; i <= q; ++ i) {
		cin >> L[i] >> R[i] >> x[i];
	}
	for (int i = 1; i <= n; ++ i) {
		ll l = 0, r = q + 1; 
		while (r - l > 1) {
			ll mid = (l + r) / 2;
			if (check (mid, i) >= sum[i]) r = mid;
			else l = mid;
		}
		if (r == q + 1) cout << "NIE\n";
		else cout << r << endl;
	}
	
	return;
}
signed main () {
	#ifdef Maga
		freopen("input", "r", stdin);
	#endif
	YOSIK();
	ll T = 1;
	//cin >> T;
	while (T --) {
		Solution ();
	}
	exit (0);
}/*

*/

Compilation message

met.cpp: In function 'll check(ll, ll)':
met.cpp:116:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |  for (int i = 0; i < v[pos].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 428 ms 23888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1196 ms 23924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6092 ms 28516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6082 ms 28760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6050 ms 28648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6075 ms 28484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6075 ms 58120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6032 ms 58268 KB Time limit exceeded
2 Halted 0 ms 0 KB -