QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455158#6462. Jewel Thiefdo_while_trueRE 1ms7696kbC++172.9kb2024-06-25 20:38:192024-06-25 20:38:20

Judging History

你现在查看的是最新测评结果

  • [2024-06-25 20:38:20]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:7696kb
  • [2024-06-25 20:38:19]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<bitset>
#include<random>
#include<array>
#include<assert.h>
#include<functional>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
	r=0;bool w=0;char ch=getchar();
	while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
	return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
const int bas=20201205;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
	int s=1;
	while(y){
		if(y&1)s=1ll*s*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return s;
}
const int N=1000010;
const ll inf=0x3f3f3f3f3f3f3f3f;
int n,m;
int b[N];
ll c[N];
ll f[N],g[N];
vll vec[310];
signed main(){
	#ifdef do_while_true
		assert(freopen("data.in","r",stdin));
	#endif
	read(n,m);
	int mx=0;
	for(int i=1;i<=n;i++)read(b[i],c[i]),cmax(mx,b[i]);
	for(int i=1;i<=n;i++)vec[b[i]].pb(c[i]);
	for(int o=1;o<=mx;o++)if(!vec[o].empty()){
		sort(vec[o].begin(),vec[o].end(),greater<int>());
		int len=vec[o].size();
		for(int i=1;i<len;i++)vec[o][i]+=vec[o][i-1];
		vec[o].insert(vec[o].begin(),0ll);
		for(int p=0;p<o;p++){
			function<void(int,int,int,int)>solve=[&](int l,int r,int L,int R){
				if(l>r)return ;
				int mid=(l/o+r/o)/2*o+p;
				int pos=0;ll mx=-inf;
				for(int i=L;i<=min(mid,R);i+=o){
					ll w=f[i]+vec[o][min(len,(mid-i)/o)];
					if(w>mx){
						mx=w;
						pos=i;
					}
				}
				g[mid]=mx;
				solve(l,mid-o,L,pos);
				solve(mid+o,r,pos,R);
			};
			int t=m;
			while(t%o!=p)--t;
			if(p<=t){
//				DE("p=%d t=%d",p,t);
				solve(p,t,p,t);
			}
		}
		for(int i=1;i<=m;i++)f[i]=max(f[i-1],g[i]),g[i]=0;
	}
	for(int i=1;i<=m;i++)cout<<f[i]<<' ';
	cerr<<'\n';
    #ifdef do_while_true
//		cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
	#endif
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7684kb

input:

4 9
2 8
1 1
3 4
5 100

output:

1 8 9 9 100 101 108 109 109 

result:

ok single line: '1 8 9 9 100 101 108 109 109 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 7696kb

input:

5 7
2 2
3 8
2 7
2 4
3 8

output:

0 7 8 11 15 16 19 

result:

ok single line: '0 7 8 11 15 16 19 '

Test #3:

score: -100
Runtime Error

input:

2 6
300 1
300 2

output:


result: