Submission #334061

# Submission time Handle Problem Language Result Execution time Memory
334061 2020-12-08T08:57:22 Z jiahng Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
13 / 100
767 ms 81024 KB
//https://oj.uz/problem/view/IZhO19_sortbooks

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
typedef pair<pi,ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
typedef pair <pi,pi> pipi;
typedef pair <ll, pi> ipi;
#define maxn 1000001

int N, M, W[maxn];
pipi A[maxn];
int ans[maxn];
int p[maxn];

int fl(int x){
	if (p[x] == x) return p[x];
	return p[x] = fl(p[x]);
}
void join(int a,int b){
	p[fl(a)] = fl(b);
}

int main(){
	fast;
	
	cin >> N >> M;
	
	FOR(i,1,N) cin >> W[i];
	FOR(i,1,M){
		cin >> A[i].s.f >> A[i].s.s >> A[i].f.f;
		A[i].f.s = i;
	}
	
	iota(p,p+N+1,0);
	
	priority_queue <ipi,vector <ipi>, greater <ipi> > pq;
	
	FOR(i,1,N-1){
		if (W[i] > W[i + 1]) pq.push(ipi(W[i] + W[i + 1], pi(i,i + 1)));
		else join(i,i+1);
	}
	
	sort(A + 1, A + M + 1);
	
	FOR(i,1,M){
		while (!pq.empty() && pq.top().f <= A[i].f.f){
			join(pq.top().s.f, pq.top().s.s);
			pq.pop();
		}
		if (fl(A[i].s.f) == fl(A[i].s.s)) ans[A[i].f.s] = 1;
		else ans[A[i].f.s] = 0;
	}
	FOR(i,1,M) cout << ans[i] << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 710 ms 65364 KB Output is correct
2 Correct 767 ms 66240 KB Output is correct
3 Correct 717 ms 65272 KB Output is correct
4 Correct 742 ms 65336 KB Output is correct
5 Correct 720 ms 81024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 8160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -