Submission #102093

# Submission time Handle Problem Language Result Execution time Memory
102093 2019-03-22T08:53:32 Z gs14004 Bitaro, who Leaps through Time (JOI19_timeleap) C++17
4 / 100
1996 ms 13864 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<lint, lint>;
const int MAXN = 600005;
const int B = 505;

int n, q;
pi a[MAXN];

struct bucket{
	lint ints, inte;
	int destination;
	lint offset;
	bool found;
	void remake(int s, int e){
		s = max(s, 1); e = min(e, 2 * n - 1);
		ints = -1e9, inte = 2e9;
		offset = 0;
		found = 0;
		for(int i=s; i<=e; i++){
			if(max(ints, a[i].first) < min(inte, a[i].second)){
				inte = min(inte, a[i].second);
				ints = max(ints, a[i].first);
			}
			else{
				found = 1; 
				if(a[i].first >= inte) ints = inte;
				if(a[i].second <= ints) inte = ints;
				int x = inte;
				for(int j=i; j<=e; j++){
					if(x < a[j].first) x = a[j].first;
					if(x > a[j].second){
						offset += x - a[j].second;
						x = a[j].second;
					}
				}
				destination = x;
				break;
			}
		}
	}
	pi process(int x){
		if(!found){
			if(x > inte) return pi(x - inte, inte);
			else return pi(0ll, max(x * 1ll, ints));
		}
		lint ret = offset + max(x - ints, 0ll);
		return pi(ret, 1ll * destination);
	}
}bkt[10000];

pi solve(int s, int e, int x){
	if(e - s <= 3*B){
		lint ans = 0;
		for(int i=s; i<=e; i++){
			if(x < a[i].first) x = a[i].first;
			if(x > a[i].second){
				ans += x - a[i].second;
				x = a[i].second;
			}
		}
		return pi(ans, x);
	}
	else{
		auto ret1 = solve(s, (s/B + 1) * B - 1, x);
		lint ans = ret1.first;
		x = ret1.second;
		for(int i=s/B+1; i<e/B; i++){
			auto nxt = bkt[i].process(x);
			ans += nxt.first;
			x = nxt.second;
		}
		auto ret2 = solve((e / B) * B, e, x);
		ans += ret2.first;
		x = ret2.second;
		return pi(ans, x);
	}
}

int main(){
	scanf("%d %d",&n,&q);
	for(int i=1; i<n; i++){
		scanf("%lld %lld",&a[i].first,&a[i].second);
		a[2*n-i] = a[i];
	}
	a[n] = pi(6, 9);
	for(int i=1; i<=2*n-1; i++){
		a[i].first -= i;
		a[i].second -= i + 1;
	}
	for(int i=0; i<=2*n-1; i+=B){
		bkt[i/B].remake(i, i + B - 1);
	}
	for(int i=0; i<q; i++){
		int t; scanf("%d",&t);
		if(t == 1){
			int p, s, e; scanf("%d %d %d",&p,&s,&e);
			a[p] = pi(s - p, e - p - 1);
			a[2*n-p] = pi(s - 2 * n + p, e - 2 * n + p - 1);
			{
				int key = p / B;
				bkt[key].remake(key * B, key * B + B - 1);
			}
			{
				int key = (2 * n - p) / B;
				bkt[key].remake(key * B, key * B + B - 1);
			}
		}
		else{
			int p, q, r, s; scanf("%d %d %d %d",&p,&q,&r,&s);
			lint ans = 0;
			if(p < r){
				q -= p;
				s -= r;
				auto dap = solve(p, r - 1, q);
				ans = dap.first + max(dap.second - s, 0ll);
			}
			else if(p > r){
				q -= 2 * n - p + 1;
				s -= 2 * n - r + 1;
				auto dap =  solve(2 * n - p + 1, 2 * n - r, q);
				ans = dap.first + max(dap.second - s, 0ll);
			}
			else{
				ans = max(q - s, 0);
			}
			printf("%lld\n", ans);
		}
	}
}

Compilation message

timeleap.cpp: In function 'int main()':
timeleap.cpp:82:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
timeleap.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&a[i].first,&a[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:96:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int t; scanf("%d",&t);
          ~~~~~^~~~~~~~~
timeleap.cpp:98:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int p, s, e; scanf("%d %d %d",&p,&s,&e);
                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:111:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int p, q, r, s; scanf("%d %d %d %d",&p,&q,&r,&s);
                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 4 ms 484 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 7 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 8 ms 384 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 8 ms 384 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 7 ms 472 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 6 ms 384 KB Output is correct
40 Correct 7 ms 384 KB Output is correct
41 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1890 ms 13716 KB Output is correct
2 Correct 1832 ms 13048 KB Output is correct
3 Correct 1833 ms 13276 KB Output is correct
4 Correct 1996 ms 12920 KB Output is correct
5 Correct 1844 ms 13612 KB Output is correct
6 Correct 1793 ms 13300 KB Output is correct
7 Incorrect 1617 ms 13864 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 4 ms 484 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 7 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 8 ms 384 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 8 ms 384 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 7 ms 472 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 6 ms 384 KB Output is correct
40 Correct 7 ms 384 KB Output is correct
41 Correct 2 ms 256 KB Output is correct
42 Correct 1890 ms 13716 KB Output is correct
43 Correct 1832 ms 13048 KB Output is correct
44 Correct 1833 ms 13276 KB Output is correct
45 Correct 1996 ms 12920 KB Output is correct
46 Correct 1844 ms 13612 KB Output is correct
47 Correct 1793 ms 13300 KB Output is correct
48 Incorrect 1617 ms 13864 KB Output isn't correct
49 Halted 0 ms 0 KB -