제출 #173424

#제출 시각아이디문제언어결과실행 시간메모리
173424TricksterHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3054 ms258672 KiB
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 1000010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>

using namespace std;

int n, q;
int v[N];
pii T[N*4];
int l, r, x;
vector <int> E[N*4];

void uni(int CEP, int SAG, int node)
{
	pii ans = {-1, -1};
	vector <int> res;
	
	int pos = 0, pos2 = 0;
	while(pos < E[CEP].size() && pos2 < E[SAG].size()) {
		if(E[CEP][pos] < E[SAG][pos2]) res.pb(E[CEP][pos++]);
		
		else res.pb(E[SAG][pos2++]);
	}
	
	int a = pos2-1;
	
	while(pos < E[CEP].size()) res.pb(E[CEP][pos++]);
	while(pos2 < E[SAG].size()) res.pb(E[SAG][pos2++]);
	
	if(T[CEP].ss == -1 || T[SAG].ss == -1) { ans = (T[CEP].ss == -1 ? T[SAG] : T[CEP]); }
	else {
		if(T[CEP].ff + T[CEP].ss >= T[SAG].ff + T[SAG].ss) ans = T[CEP];
		else ans = T[SAG];
	}
	
	if(a != -1) {
		int x = E[SAG][a];
		
		if(ans.ss == -1 || ans.ff + ans.ss < E[CEP].back() + x) ans = {E[CEP].back(), x};
	}
	
	if(T[node].ss == -1 || (ans.ss != -1 && ans.ff+ans.ss >= T[node].ff + T[node].ss)) T[node] = ans;
	
	E[node].clear();
	for(auto i: res) E[node].pb(i);
}

void build(int l, int r, int node)
{
	if(l == r) {
		T[node] = {v[l], -1};
		E[node].pb(v[l]);
		return;
	}
	
	build(l, (l+r)/2, node*2);
	build((l+r)/2+1, r, node*2+1);
	
	uni(node*2, node*2+1, node);
} 
void tap(int a, int b, int l, int r, int node)
{
	if(l > b || r < a) return;
	
	if(l >= a && r <= b) {
		uni(0, node, 0);
		return;
	}
	
	tap(a, b, l, (l+r)/2, node*2);
	tap(a, b, (l+r)/2+1, r, node*2+1);
}

int main()
{
	scanf("%d%d", &n, &q);
	
	for(int i = 1; i <= n; i++)
		scanf("%d", &v[i]);
	
	build(1, n, 1);
	
	for(int i = 1; i <= q; i++) {
		scanf("%d%d%d", &l, &r, &x);
		
		E[0].clear();
		T[0] = {-1, -1};
		tap(l, r, 1, n, 1);
		
		if(T[0].ss == -1 || T[0].ff + T[0].ss <= x) puts("1");
		else puts("0");
	}
}

컴파일 시 표준 에러 (stderr) 메시지

sortbooks.cpp: In function 'void uni(int, int, int)':
sortbooks.cpp:32:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pos < E[CEP].size() && pos2 < E[SAG].size()) {
        ~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:32:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pos < E[CEP].size() && pos2 < E[SAG].size()) {
                               ~~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:40:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pos < E[CEP].size()) res.pb(E[CEP][pos++]);
        ~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:41:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pos2 < E[SAG].size()) res.pb(E[SAG][pos2++]);
        ~~~~~^~~~~~~~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &v[i]);
   ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:97:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &l, &r, &x);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...