Submission #22600

# Submission time Handle Problem Language Result Execution time Memory
22600 2017-04-30T05:51:02 Z 버거킹 송죽SK점 우수고객(#1039, Namnamseo, khsoo01) Donut-shaped Enclosure (KRIII5_DE) C++11
7 / 7
763 ms 49440 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
const ll inf = (1LL << 60);
#define yn namseo

int n;
ll l, r;

typedef tuple<ll,ll,ll,ll,ll> rect;
vector<rect> rs;

void in(){
	scanf("%d%lld%lld", &n, &l, &r);
	for(int i=1; i<=n; ++i){
		ll x, y, s;
		scanf("%lld%lld%lld", &x, &y, &s);
		rs.emplace_back(x-2*r, x, y-2*r, y, s);
		rs.emplace_back(x-r-l+1, x-(r-l)-1, y-r-l+1, y-(r-l)-1, -s);
	}
}

vector<ll> YS;
int yn;

void compress(){
	YS.pb(inf);
	for(auto& tmp:rs){
		int d=get<2>(tmp), u=get<3>(tmp);
		YS.pb(d);
		YS.pb(u+1);
	}
	sort(all(YS));
	YS.erase(unique(all(YS)), YS.end());
	yn=YS.size()-1;
}

typedef tuple<ll,ll,ll,ll> Q;
vector<Q> qs;
void make_query(){
	qs.reserve(4*n);
	for(auto& tmp:rs){
		ll l,r,d,u,s; tie(l,r,d,u,s)=tmp;
		d=lower_bound(all(YS), d) - YS.begin();
		u=lower_bound(all(YS), u+1) - YS.begin() - 1;
		qs.emplace_back(l, d, u, s);
		qs.emplace_back(r+1, d, u, -s);
	}
	sort(all(qs));
}

struct SEG {
	int N;
	ll tmax[1048576];
	ll lazy[1048576];
	
	void init(int n){
		N=n;
	}
	
	inline void pd(int p, int l, int r){
		if(l==r) return;
		ll d=lazy[p];
		tmax[p*2] += d;
		lazy[p*2] += d;
		tmax[p*2+1] += d;
		lazy[p*2+1] += d;
		lazy[p]=0;
	}
	
	void update(int l, int r, int s, int p, int ml, int mr){
		pd(p, ml, mr);
		if(l<=ml && mr<=r){
			tmax[p]+=s;
			lazy[p]+=s;
			return;
		}
		if(r<ml || mr<l) return;
		int mid=(ml+mr)/2;
		update(l,r,s, p*2, ml, mid);
		update(l,r,s, p*2+1, mid+1, mr);
		tmax[p]=max(tmax[p*2], tmax[p*2+1]);
	}
	
	ll get_max(){
		return tmax[1];
	}

} seg;

int main()
{
	//freopen("in", "r", stdin);
	in();
	compress();
	make_query();
	
	seg.init(yn);
	ll ans = 0;
	ll last_x = -inf;
	for(auto& q:qs){
		ll x, d, u, s;
		tie(x, d, u, s) = q;
		if(last_x != x) ans=max(ans, seg.get_max());
		last_x = x;
		seg.update(d, u, s, 1, 0, yn-1);
	}
	printf("%lld\n", ans);
    return 0;
}

Compilation message

DE.cpp: In function 'void in()':
DE.cpp:20:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%lld%lld", &n, &l, &r);
                                 ^
DE.cpp:23:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &x, &y, &s);
                                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 18424 KB Output is correct
2 Correct 0 ms 18424 KB Output is correct
3 Correct 0 ms 18424 KB Output is correct
4 Correct 0 ms 18424 KB Output is correct
5 Correct 0 ms 18424 KB Output is correct
6 Correct 0 ms 18568 KB Output is correct
7 Correct 0 ms 18580 KB Output is correct
8 Correct 0 ms 18580 KB Output is correct
9 Correct 0 ms 18752 KB Output is correct
10 Correct 3 ms 18784 KB Output is correct
11 Correct 3 ms 18784 KB Output is correct
12 Correct 3 ms 18784 KB Output is correct
13 Correct 3 ms 18784 KB Output is correct
14 Correct 3 ms 18784 KB Output is correct
15 Correct 3 ms 18784 KB Output is correct
16 Correct 3 ms 18784 KB Output is correct
17 Correct 3 ms 18784 KB Output is correct
18 Correct 3 ms 18784 KB Output is correct
19 Correct 3 ms 18784 KB Output is correct
20 Correct 3 ms 18784 KB Output is correct
21 Correct 3 ms 18784 KB Output is correct
22 Correct 3 ms 18784 KB Output is correct
23 Correct 3 ms 18784 KB Output is correct
24 Correct 3 ms 18784 KB Output is correct
25 Correct 3 ms 18784 KB Output is correct
26 Correct 3 ms 18784 KB Output is correct
27 Correct 3 ms 18784 KB Output is correct
28 Correct 3 ms 18784 KB Output is correct
29 Correct 0 ms 18784 KB Output is correct
30 Correct 3 ms 18784 KB Output is correct
31 Correct 0 ms 18784 KB Output is correct
32 Correct 3 ms 18784 KB Output is correct
33 Correct 0 ms 18784 KB Output is correct
34 Correct 0 ms 18784 KB Output is correct
35 Correct 0 ms 18784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 18424 KB Output is correct
2 Correct 0 ms 18424 KB Output is correct
3 Correct 0 ms 18424 KB Output is correct
4 Correct 0 ms 18424 KB Output is correct
5 Correct 0 ms 18424 KB Output is correct
6 Correct 0 ms 18568 KB Output is correct
7 Correct 0 ms 18580 KB Output is correct
8 Correct 0 ms 18580 KB Output is correct
9 Correct 0 ms 18752 KB Output is correct
10 Correct 3 ms 18784 KB Output is correct
11 Correct 3 ms 18784 KB Output is correct
12 Correct 3 ms 18784 KB Output is correct
13 Correct 3 ms 18784 KB Output is correct
14 Correct 3 ms 18784 KB Output is correct
15 Correct 3 ms 18784 KB Output is correct
16 Correct 3 ms 18784 KB Output is correct
17 Correct 3 ms 18784 KB Output is correct
18 Correct 3 ms 18784 KB Output is correct
19 Correct 3 ms 18784 KB Output is correct
20 Correct 3 ms 18784 KB Output is correct
21 Correct 3 ms 18784 KB Output is correct
22 Correct 3 ms 18784 KB Output is correct
23 Correct 3 ms 18784 KB Output is correct
24 Correct 3 ms 18784 KB Output is correct
25 Correct 3 ms 18784 KB Output is correct
26 Correct 3 ms 18784 KB Output is correct
27 Correct 3 ms 18784 KB Output is correct
28 Correct 3 ms 18784 KB Output is correct
29 Correct 0 ms 18784 KB Output is correct
30 Correct 3 ms 18784 KB Output is correct
31 Correct 0 ms 18784 KB Output is correct
32 Correct 3 ms 18784 KB Output is correct
33 Correct 0 ms 18784 KB Output is correct
34 Correct 0 ms 18784 KB Output is correct
35 Correct 0 ms 18784 KB Output is correct
36 Correct 0 ms 18424 KB Output is correct
37 Correct 0 ms 18580 KB Output is correct
38 Correct 3 ms 18808 KB Output is correct
39 Correct 6 ms 18916 KB Output is correct
40 Correct 13 ms 19472 KB Output is correct
41 Correct 13 ms 20220 KB Output is correct
42 Correct 23 ms 20424 KB Output is correct
43 Correct 29 ms 20660 KB Output is correct
44 Correct 46 ms 22076 KB Output is correct
45 Correct 53 ms 22372 KB Output is correct
46 Correct 63 ms 22700 KB Output is correct
47 Correct 76 ms 25364 KB Output is correct
48 Correct 109 ms 25756 KB Output is correct
49 Correct 299 ms 34512 KB Output is correct
50 Correct 299 ms 34668 KB Output is correct
51 Correct 689 ms 49436 KB Output is correct
52 Correct 586 ms 49436 KB Output is correct
53 Correct 649 ms 49436 KB Output is correct
54 Correct 689 ms 49436 KB Output is correct
55 Correct 616 ms 49440 KB Output is correct
56 Correct 656 ms 49440 KB Output is correct
57 Correct 683 ms 49440 KB Output is correct
58 Correct 763 ms 49440 KB Output is correct
59 Correct 609 ms 49440 KB Output is correct
60 Correct 646 ms 49440 KB Output is correct
61 Correct 6 ms 18916 KB Output is correct
62 Correct 59 ms 22372 KB Output is correct
63 Correct 129 ms 26240 KB Output is correct
64 Correct 359 ms 33972 KB Output is correct
65 Correct 636 ms 49440 KB Output is correct
66 Correct 393 ms 49440 KB Output is correct
67 Correct 323 ms 49440 KB Output is correct
68 Correct 383 ms 49440 KB Output is correct
69 Correct 409 ms 49440 KB Output is correct
70 Correct 516 ms 49440 KB Output is correct
71 Correct 429 ms 49440 KB Output is correct
72 Correct 446 ms 49440 KB Output is correct
73 Correct 506 ms 49440 KB Output is correct
74 Correct 466 ms 49440 KB Output is correct
75 Correct 496 ms 49440 KB Output is correct
76 Correct 513 ms 49440 KB Output is correct
77 Correct 546 ms 49440 KB Output is correct
78 Correct 549 ms 49440 KB Output is correct
79 Correct 556 ms 49440 KB Output is correct
80 Correct 553 ms 49440 KB Output is correct