답안 #68448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68448 2018-08-17T07:17:14 Z MrTEK 금 캐기 (IZhO14_divide) C++14
48 / 100
117 ms 9040 KB
#include <bits/stdc++.h>
 
using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define fi first
#define sc second
#define cout maltahsin
#define left ind + ind
#define right ind + ind + 1
#define mid (l + r) / 2 
#define d1(w) cerr<<#w<<":"<<w<<endl;
#define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl;
#define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl;
#define FAST_IO ios_base::sync_with_stdio(false);
#define endl '\n'
 
const int maxn = 620;
const long long LINF = 1e18;
const int LOG = 31;
const int INF = 1e9 + 5;
const int N = 1e5 + 5;
const int M = 1e5 + 5;
const int SQ = 350;
const int MOD = 998244353;
 
typedef pair <int,int> pii;

vector <pair <long long,int> > v;

int n,x[N],g[N],d[N],seg[N << 2],a[N],b[N];
long long ans,pred[N],preg[N];

void update(int ind,int l,int r,int w,int val) {
	if (l > w || r < w) return;
	if (l == w && r == w) {
		seg[ind] = min(seg[ind],val);
		return;
	}
	update(left,l,mid,w,val);
	update(right,mid + 1,r,w,val);
	seg[ind] = min(seg[left],seg[right]);
}

int get(int ind,int l,int r,int lw,int rw) {
	if (l > rw || r < lw) return INF;
	if (l >= lw && r <= rw) return seg[ind];
	return min(get(left,l,mid,lw,rw),get(right,mid + 1,r,lw,rw));
}


int main() {

	scanf("%d",&n);

	for (int i = 1 ; i <= n ; i++) {
		scanf("%d %d %d",&x[i],&g[i],&d[i]);
		pred[i] = pred[i - 1] + d[i];
		preg[i] = preg[i - 1] + g[i];
		v.pb(mp(pred[i] - x[i],i));
		v.pb(mp(pred[i - 1] - x[i],i));
	}

	sort(v.begin(),v.end());

	for (int i = 0, lst = 0; i < len(v) ; i++) {
		if (i == 0 || v[i - 1].fi != v[i].fi) lst++;
		if (b[v[i].sc]) a[v[i].sc] = lst;
		else b[v[i].sc] = lst;
	}

	for (int i = 0 ; i < (N << 2) ; i++) seg[i] = INF;

	for (int i = 1 ; i <= n ; i++) {
		update(1,1,2 * n,b[i],i);
		int lst = get(1,1,2 * n,1,a[i]);
		if (lst != INF) ans = max(preg[i] - preg[lst - 1],ans);
	}
	printf("%lld\n",ans);

}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
divide.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&x[i],&g[i],&d[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1916 KB Output is correct
2 Correct 5 ms 2020 KB Output is correct
3 Correct 8 ms 2100 KB Output is correct
4 Correct 4 ms 2100 KB Output is correct
5 Correct 4 ms 2156 KB Output is correct
6 Correct 3 ms 2156 KB Output is correct
7 Correct 4 ms 2156 KB Output is correct
8 Correct 4 ms 2156 KB Output is correct
9 Correct 4 ms 2156 KB Output is correct
10 Correct 4 ms 2156 KB Output is correct
11 Correct 4 ms 2156 KB Output is correct
12 Correct 4 ms 2156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2156 KB Output is correct
2 Correct 4 ms 2212 KB Output is correct
3 Correct 4 ms 2212 KB Output is correct
4 Correct 5 ms 2284 KB Output is correct
5 Correct 5 ms 2284 KB Output is correct
6 Correct 6 ms 2284 KB Output is correct
7 Correct 5 ms 2284 KB Output is correct
8 Correct 6 ms 2284 KB Output is correct
9 Correct 6 ms 2284 KB Output is correct
10 Correct 6 ms 2300 KB Output is correct
11 Correct 11 ms 2664 KB Output is correct
12 Correct 11 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2668 KB Output is correct
2 Correct 14 ms 2916 KB Output is correct
3 Correct 14 ms 2944 KB Output is correct
4 Correct 71 ms 5592 KB Output is correct
5 Correct 68 ms 5592 KB Output is correct
6 Correct 117 ms 8912 KB Output is correct
7 Correct 100 ms 8912 KB Output is correct
8 Correct 90 ms 8912 KB Output is correct
9 Correct 98 ms 9040 KB Output is correct
10 Incorrect 96 ms 9040 KB Output isn't correct
11 Halted 0 ms 0 KB -