Submission #501627

# Submission time Handle Problem Language Result Execution time Memory
501627 2022-01-04T08:47:59 Z Nuraly_Serikbay Meteors (POI11_met) C++14
0 / 100
6000 ms 47988 KB
#include <bits/stdc++.h>
  
#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 ;   
 
struct edge {
	ll a, b, len;	

    bool operator<(const edge& other) {
        return len < other.len;
    }
};


bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second < b.second);
}
 
void pre (ll a) {
    cout << fixed << setprecision(a);
    return;
}

ll n, m, q;
ll a[N], sum[N], mod[N], L[N], R[N], cost[N];
vector <ll> p[N];

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

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

ll get (ll l, ll r, ll v, ll pos) {
	if (l == r) {
		return mod[v];
	}
	push (v, l, r);
	ll mid = l + r >> 1;
	if (pos <= mid) {
		return get (l, mid, v * 2, pos);
	} else {
		return get (mid + 1, r, v * 2 + 1, pos);
	}
}

ll check (ll pos, ll id) {
	ll ans = 0;
	for (int i = 1; i <= pos; ++ i) {
		if (L[i] > R[i]) {
			update (L[i], m, 1, m, 1, cost[i]);
			update (1, R[i], 1, m, 1, cost[i]);
		} else {
			update (L[i], R[i], 1, m, 1, cost[i]);
		}
	}
	for (int i = 0; i < p[id].size(); ++ i) {
		ans += get (1, m, 1, p[id][i]);
	}
	for (int i = 1; i <= m * 4; ++ i) mod[i] = 0;
	return ans;
}

void Solution (/*Nuraly.Serikbay*/) {
	cin >> n >> m;
	for (int i = 1; i <= m; ++ i) {
		cin >> a[i];
		p[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] >> cost[i];	
	}
	for (int i = 1; i <= n; ++ i) {
		ll l = 1, r = q;
		while (r - l > 0) {
			ll mid = l + r >> 1;
			if (check (mid, i) >= sum[i]) {
				r = mid;
			} else {
				l = mid + 1;
			}
		}
		//cout << check (r, i) << ' ';
		if (check (r, i) < sum[i]) cout << "NIE\n";
		else cout << r << '\n';
	}
	return;
}
main () {
	YOSIK();
	ll T = 1;
	//cin >> T;
	while (T --) {
		Solution ();
	}
	exit (0);
}/*

*/

Compilation message

met.cpp: In function 'void update(ll, ll, ll, ll, ll, ll)':
met.cpp:88:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   88 |  ll mid = tl + tr >> 1;
      |           ~~~^~~~
met.cpp: In function 'll get(ll, ll, ll, ll)':
met.cpp:101:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  101 |  ll mid = l + r >> 1;
      |           ~~^~~
met.cpp: In function 'll check(ll, ll)':
met.cpp:119: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]
  119 |  for (int i = 0; i < p[id].size(); ++ i) {
      |                  ~~^~~~~~~~~~~~~~
met.cpp: In function 'void Solution()':
met.cpp:142:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  142 |    ll mid = l + r >> 1;
      |             ~~^~~
met.cpp: At global scope:
met.cpp:155:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  155 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 230 ms 23920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 492 ms 23924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6042 ms 28136 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6026 ms 28264 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6068 ms 27740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6045 ms 28008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6097 ms 47988 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6054 ms 47684 KB Time limit exceeded
2 Halted 0 ms 0 KB -