Submission #118141

# Submission time Handle Problem Language Result Execution time Memory
118141 2019-06-18T08:47:44 Z 김세빈(#2888) Bitaro, who Leaps through Time (JOI19_timeleap) C++14
0 / 100
591 ms 79976 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

struct node{
	ll t, l, r, x1, x2, v;
	node() {}
	node(ll l, ll r) : t(1), l(l), r(r) {}
	node(ll l, ll r, ll x) : t(2), l(l), r(r), x1(x), x2(x), v(0) {}
	
	pll pass(ll x)
	{
		if(t == 1){
			if(l <= x && x <= r) return pll(x, 0);
			else if(x < l) return pll(l, 0);
			else return pll(r, x - r);
		}
		else{
			ll _v = v;
			
			if(x < l) x = l;
			else if(r < x) _v += x - r, x = r;
			if(x > x1) _v += x - x1;
			
			return pll(x2, _v);
		}
	}
	
	node operator+ (node n)
	{
		if(t == 1 && n.t == 1){
			if(max(l, n.l) <= min(r, n.r)){
				return node(max(l, n.l), min(r, n.r));
			}
			else if(r < n.l) return node(l, r, n.l);
			else return node(l, r, n.r);
		}
		else if(t == 1 && n.t == 2){
			node ret = n;
			
			if(max(l, n.l) <= min(r, n.r)){
				ret.l = max(l, n.l);
				ret.r = min(r, n.r);
			}
			else if(r < n.l){
				ret.x1 = n.l;
				if(n.l > n.x1) ret.v += n.l - n.x1;
			}
			else{
				ret.x1 = n.r;
				if(n.r > n.x1) ret.v += n.r - n.x1;
			}
			
			return ret;
		}
		else if(t == 2 && n.t == 1){
			node ret(l, r, x1);
			
			ret.v = v;
			if(n.l <= x2 && x2 <= n.r) ret.x2 = x2;
			else if(x2 < n.l) ret.x2 = n.l;
			else if(n.r < x2) ret.x2 = n.r, ret.v += x2 - n.r;
			
			return ret;
		}
		else{
			node ret(l, r, x1);
			ll _x2, _v;
			
			tie(_x2, _v) = n.pass(x2);
			ret.x2 = _x2; ret.v = v + _v;
			
			return ret;
		}
	}
};

node T1[1101010], T2[1101010];
ll n, sz;

void update(node *T, ll p)
{
	p = p + sz >> 1;
	for(; p; p>>=1){
		T[p] = T[p << 1] + T[p << 1 | 1];
	}
}

node get_sum(node *T, ll l, ll r)
{
	node sl, sr;
	bool fl = 0, fr = 0;
	
	l += sz; r += sz;
	
	for(; l<r; ){
		if(l & 1){
			if(!fl) sl = T[l], fl = 1;
			else sl = sl + T[l];
		}
		if(~r & 1){
			if(!fr) sr = T[r], fr = 1;
			else sr = T[r] + sr;
		}
		l = l + 1 >> 1;
		r = r - 1 >> 1;
	}
	
	if(l == r){
		if(fl && fr) return sl + T[l] + sr;
		else if(fl && !fr) return sl + T[l];
		else if(!fl && fr) return T[l] + sr;
		else return T[l];
	}
	else{
		if(fl && fr) return sl + sr;
		else if(fl && !fr) return sl;
		else if(!fl && fr) return sr;
		else 1 / 0;
	}
}

int main()
{
	ll q, i, t, l, r, x, y, z, s, e, v;
	
	scanf("%lld%lld", &n, &q);
	
	for(sz=1; sz<=n; sz<<=1);
	
	for(i=1; i<n; i++){
		scanf("%lld%lld", &l, &r);
		T1[sz + i] = node(l - i, r - i - 1);
		T2[sz + n - i] = node(l - n + i, r - n + i - 1);
	}
	
	for(i=sz-1; i>=1; i--){
		T1[i] = T1[i << 1] + T1[i << 1 | 1];
		T2[i] = T2[i << 1] + T2[i << 1 | 1];
	}
	
	for(; q--; ){
		scanf("%lld", &t);
		if(t == 1){
			scanf("%lld%lld%lld", &i, &l, &r);
			T1[sz + i] = node(l - i, r - i - 1);
			T2[sz + n - i] = node(l - n + i, r - n + i - 1);
			update(T1, i); update(T2, n - i);
		}
		else{
			scanf("%lld%lld%lld%lld", &s, &x, &e, &y);
			if(s == e) printf("%lld\n", max(0ll, x - y));
			else if(s < e){
				x -= s; y -= e;
				tie(z, v) = get_sum(T1, s, e - 1).pass(x);
				printf("%lld\n", v + max(0ll, z - y));
			}
			else{
				s = n - s + 1; e = n - e + 1;
				x -= s; y -= e;
				tie(z, v) = get_sum(T2, s, e - 1).pass(x);
				printf("%lld\n", v + max(0ll, z - y));
			}
		}
	}
	
	return 0;
}

Compilation message

timeleap.cpp: In function 'void update(node*, ll)':
timeleap.cpp:86:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  p = p + sz >> 1;
      ~~^~~~
timeleap.cpp: In function 'node get_sum(node*, ll, ll)':
timeleap.cpp:108:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   l = l + 1 >> 1;
       ~~^~~
timeleap.cpp:109:9: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   r = r - 1 >> 1;
       ~~^~~
timeleap.cpp:122:10: warning: division by zero [-Wdiv-by-zero]
   else 1 / 0;
        ~~^~~
timeleap.cpp:122:10: warning: statement has no effect [-Wunused-value]
timeleap.cpp:124:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
timeleap.cpp: In function 'int main()':
timeleap.cpp:130:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
timeleap.cpp:135:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
timeleap.cpp:146:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &t);
   ~~~~~^~~~~~~~~~~~
timeleap.cpp:148:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld%lld%lld", &i, &l, &r);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:154:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld%lld%lld%lld", &s, &x, &e, &y);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 591 ms 79976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -