Submission #709856

# Submission time Handle Problem Language Result Execution time Memory
709856 2023-03-14T17:16:25 Z myrcella Catfish Farm (IOI22_fish) C++17
9 / 100
464 ms 37200 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,0,N) 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);
//			debug(tmp);debug(x.fi),debug(x.se);
			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;
      |          ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 101 ms 15900 KB Output is correct
2 Correct 130 ms 18476 KB Output is correct
3 Correct 57 ms 9088 KB Output is correct
4 Correct 56 ms 9036 KB Output is correct
5 Correct 361 ms 34380 KB Output is correct
6 Correct 464 ms 37200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 183 ms 22824 KB Output is correct
3 Correct 221 ms 27848 KB Output is correct
4 Correct 112 ms 17248 KB Output is correct
5 Correct 126 ms 18452 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7368 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7360 KB Output is correct
10 Correct 59 ms 8980 KB Output is correct
11 Correct 74 ms 9024 KB Output is correct
12 Correct 134 ms 21412 KB Output is correct
13 Correct 162 ms 22456 KB Output is correct
14 Correct 122 ms 19416 KB Output is correct
15 Correct 131 ms 18236 KB Output is correct
16 Correct 121 ms 19428 KB Output is correct
17 Correct 133 ms 20020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8992 KB Output is correct
2 Correct 39 ms 9012 KB Output is correct
3 Incorrect 105 ms 12748 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '19431122999201'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 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 4 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '195553354921'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 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 4 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '195553354921'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 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 4 ms 7380 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '195553354921'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8992 KB Output is correct
2 Correct 39 ms 9012 KB Output is correct
3 Incorrect 105 ms 12748 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '19431122999201'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 101 ms 15900 KB Output is correct
2 Correct 130 ms 18476 KB Output is correct
3 Correct 57 ms 9088 KB Output is correct
4 Correct 56 ms 9036 KB Output is correct
5 Correct 361 ms 34380 KB Output is correct
6 Correct 464 ms 37200 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 183 ms 22824 KB Output is correct
9 Correct 221 ms 27848 KB Output is correct
10 Correct 112 ms 17248 KB Output is correct
11 Correct 126 ms 18452 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7368 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 5 ms 7360 KB Output is correct
16 Correct 59 ms 8980 KB Output is correct
17 Correct 74 ms 9024 KB Output is correct
18 Correct 134 ms 21412 KB Output is correct
19 Correct 162 ms 22456 KB Output is correct
20 Correct 122 ms 19416 KB Output is correct
21 Correct 131 ms 18236 KB Output is correct
22 Correct 121 ms 19428 KB Output is correct
23 Correct 133 ms 20020 KB Output is correct
24 Correct 59 ms 8992 KB Output is correct
25 Correct 39 ms 9012 KB Output is correct
26 Incorrect 105 ms 12748 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '19431122999201'
27 Halted 0 ms 0 KB -