답안 #709853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709853 2023-03-14T17:08:43 Z myrcella 메기 농장 (IOI22_fish) C++17
0 / 100
182 ms 25628 KB
//by szh
#include<bits/stdc++.h>
#include "fish.h"

using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn = 300010;
ll tree[2][maxn],add[2][maxn];
int y[maxn];
int xmax,ymax;
vector <pii> fish[maxn];
ll hi0[maxn],hin[maxn];
ll sum[maxn];

void push_down(int id,int c) {
	if (add[id][c]==0) return;
	tree[id][c<<1] = max(tree[id][c<<1],add[id][c]);
	add[id][c<<1] = max(add[id][c<<1],add[id][c]);
	tree[id][c<<1|1] = max(tree[id][c<<1|1],add[id][c]);
	add[id][c<<1|1] = max(add[id][c<<1|1],add[id][c]);
	add[id][c]=0;
}

void update(int id,int c,int cl,int cr,int l,int r,ll val) {
	if (l<=cl and cr<=r) {
		add[id][c] = max(add[id][c],val);
		tree[id][c] = max(tree[id][c],val);
		return;
	}
	push_down(id,c);
	int mid=cl+cr>>1;
	if (l<=mid) update(id,c<<1,cl,mid,l,r,val);
	if (r>mid) update(id,c<<1|1,mid+1,cr,l,r,val);
	tree[id][c] = max(tree[id][c<<1],tree[id][c<<1|1]);
	return;
}

ll query(int id,int c,int cl,int cr,int pos) {
	if (cl==cr) return tree[id][c];
	push_down(id,c);
	int mid=cl+cr>>1;
	if (pos<=mid) return query(id,c<<1,cl,mid,pos);
	else return query(id,c<<1|1,mid+1,cr,pos);
}

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W) {
	rep(i,0,M) {
		y[i] = Y[i];
		y[i]++;
		fish[X[i]].pb({y[i],W[i]});
		sum[X[i]]+=W[i];
	}
	rep(i,1,N+1) sort(ALL(fish[i]));
	rep(i,1,N) {
		//increasing
		for (pair<int,ll> x:fish[i-1]) {
			ll tmp = query(0,1,0,N,x.fi-1);
			update(0,1,0,N,x.fi,N,tmp+x.se);
		}
		for (int j = SZ(fish[i])-1;j>=0;j--) {
			pair<int,ll> x = fish[i][j];
			ll tmp = query(1,1,0,N,x.fi);
			update(1,1,0,N,0,x.fi-1,tmp+x.se);
		}
		hi0[i] = query(1,1,0,N,0);
		hin[i] = query(0,1,0,N,N);
//		rep(j,0,N+1) cout<<i<<" "<<j<<" "<<query(0,1,0,N,j)<<" "<<query(1,1,0,N,j)<<endl;
		update(0,1,0,N,0,N,hi0[i-1]);
		if (i>=2) update(1,1,0,N,0,N,hin[i-2]+sum[i-1]);
		int tmp1 = query(1,1,0,N,N), tmp2 = query(0,1,0,N,N);
		update(0,1,0,N,N,N,max(tmp1,tmp2));
		update(1,1,0,N,0,N,max(tmp1,tmp2));
		
//		rep(j,0,N+1) cout<<i<<" "<<j<<" "<<query(0,1,0,N,j)<<" "<<query(1,1,0,N,j)<<endl;
	}
  return max(tree[0][1],tree[1][1]);
}

Compilation message

fish.cpp: In function 'void update(int, int, int, int, int, int, long long int)':
fish.cpp:50:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |  int mid=cl+cr>>1;
      |          ~~^~~
fish.cpp: In function 'long long int query(int, int, int, int, int)':
fish.cpp:60:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |  int mid=cl+cr>>1;
      |          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 108 ms 17344 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '333535382144'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Incorrect 182 ms 25628 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40479414836090'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 9100 KB Output is correct
2 Correct 40 ms 8932 KB Output is correct
3 Incorrect 104 ms 13748 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '19431122999201'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7316 KB Output is correct
3 Correct 4 ms 7368 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Incorrect 5 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '195553354921'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7316 KB Output is correct
3 Correct 4 ms 7368 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Incorrect 5 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '195553354921'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7316 KB Output is correct
3 Correct 4 ms 7368 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Incorrect 5 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '195553354921'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 9100 KB Output is correct
2 Correct 40 ms 8932 KB Output is correct
3 Incorrect 104 ms 13748 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '19431122999201'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 108 ms 17344 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '333535382144'
2 Halted 0 ms 0 KB -