Submission #256528

# Submission time Handle Problem Language Result Execution time Memory
256528 2020-08-02T19:39:09 Z jainbot27 Just Long Neckties (JOI20_ho_t1) C++17
0 / 100
0 ms 256 KB
//Author: jainbot27
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;


#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define FOR(x, y, z) for(int x = y; x < z; x++)
#define ROF(x, y, z) for(int x = y; x > z; x--)
#define all(x) x.begin(), x.end()


const char nl = '\n';
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;


str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
	str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
	bool fst = 1; str res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += ts(x);
	}
	res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
	return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << ts(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }


#ifdef D 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif


template<class T> struct Seg {
	const T sta = 0;
	T comb(T a, T b){
		return max(a, b); 
	}
	int n; vector<T> seg;
	void init(int nn){
		n = nn;
		seg.assign(3*n, sta);
	}
	void pull(int q){
		seg[q] = comb(seg[2*q], seg[2*q+1]);
	}
	void update(int q, T val){
		seg[q+=n] = val; for(q/=2; q!=0;q/=2) pull(q);
	}
	T query(int l, int r){
		T ri = sta, la = sta;
		for(l += n, r+= n+1; l < r; l/=2, r/=2){
			if(l&1) ri = comb(ri, seg[l++]);
			if(r&1) la = comb(seg[--r], la);
		}
		return comb(ri, la);
	}
};
const int N = 2e5 + 10;
ll n, b[N], c[N], d[N], an[N];
Seg<ll> seg1, seg2;
pll a[N];

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i =0; i < n + 1; i++){
		cin >> a[i].f;	
		a[i].s = i;
	}	
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}
	sort(a, a + n + 1);
	sort(b, b + n);
	seg1.init(n + 2);
	seg2.init(n + 2);
	for(int i = 0; i < n; i++){
		c[i] = max(a[i].f - b[i], 0LL);
		dbg(c[i]);
		seg1.update(i, c[i]);		
	}
	for(int i = 0; i < n; i++){
		d[i] = max(a[i + 1].f - b[i], 0LL); 
		dbg(d[i]);
		seg2.update(i, d[i]);
	}
	for(int i = 0; i < n + 1; i++){
		int idx = i-1;
		ll ans = seg2.query(i, n);
		dbg(ans);
		if(idx>=0){
			ans = max(seg1.query(0, idx), ans);
		}
		dbg(ans);
		an[a[i].s] = ans; 
	}
	for(int i = 0; i < n + 1; i++){
		cout << an[i] << " "[i == n];
	}
}

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:114:12: warning: statement has no effect [-Wunused-value]
   dbg(c[i]);
            ^
ho_t1.cpp:119:12: warning: statement has no effect [-Wunused-value]
   dbg(d[i]);
            ^
ho_t1.cpp:125:11: warning: statement has no effect [-Wunused-value]
   dbg(ans);
           ^
ho_t1.cpp:129:11: warning: statement has no effect [-Wunused-value]
   dbg(ans);
           ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -