1.题目描述:
2.题意:
略。
3.思路:
1)纯模拟。 用优先队列模拟,T飞~。
部分代码:
typedef vector<ll> VLL;
ll n,m,q,u,v,t;
priority_queue<ll> Q;
li void solve()
{
m=read(),q=read(),u=read(),v=read(),t=read();
while(n--) Q.push(read());
rep(i,1,m+1)
{
ll tmp=Q.top();Q.pop();
if(!(i%t)) write(tmp,' ');
VLL T;
while(sz(Q))
{
ll tmp=Q.top();Q.pop();
T.pb(tmp+q);
}
rep(i,0,sz(T)) Q.push(T[i]);
ll t1=tmp*u/v;
Q.push(t1);
Q.push(tmp-t1);
}
cout<<"\n";
int cnt=1;
while(sz(Q))
{
ll tmp=Q.top();Q.pop();
if(!(cnt++%t)) write(tmp,' ');
}
//puts("");
}
int main()
{
//srand(time(0));
//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//for(int QwQ=read();QwQ;QwQ--) solve();
while(~scanf("%lld",&n)) solve();
return 0;
}
2)优化+堆。 我们用一个偏移量记录下当前加的Q,然后再在运算的时候加上Q,存储减去Q。但是很遗憾,这里不能单纯用这种模拟的方法。O(mlogm)。再次T飞~。
部分代码:
ll n,m,q,u,v,t;
priority_queue<ll> Q;
li void solve()
{
m=read(),q=read(),u=read(),v=read(),t=read();
while(n--) Q.push(read());
ll delta=0;
rep(i,1,m+1)
{
ll x=Q.top()+delta;Q.pop();
if(!(i%t)) write(x,' ');
ll lef=x*u/v;ll rig=x-lef;
delta+=q;
Q.push(lef-delta);
Q.push(rig-delta);
}
cout<<"\n";
int cnt=1;
while(sz(Q))
{
ll tmp=Q.top()+delta;Q.pop();
if(!(cnt++%t)) write(tmp,' ');
}
//puts("");
}
int main()
{
//srand(time(0));
//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//for(int QwQ=read();QwQ;QwQ--) solve();
while(~scanf("%lld",&n)) solve();
return 0;
}
3)队列+性质【正解】。考虑两个数字 ai>=aj,先将ai分成 li,ri,然后在某个时刻将aj分成lj,rj。可以证明:li>=lj && ri>=rj。【证明:我不会(理直气壮)】(给一个直观理解:假设ai与aj顺序切割,那么就会有:[pai]+q>[p(aj+q)],我们把前面的加号放进去:[pai+q]>[paj+pq] 已知:p<1,aj<ai,那么前者里面是比后者大的,那么去掉取整无妨(具有单调性))。
代码:
//AcWing 133. 蚯蚓
//#include<bits/stdc++.h>
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
//#include<random>
#include<cstdlib>
#include<ctime>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define FAST ios::sync_with_stdio(false)
#define DEV_RND ((int)rand()*RAND_MAX+rand())
#define RND(L,R) (DEV_RND%((R)-(L)+1)+(L))
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,n,a) for(int i=n-1;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define li inline
#define re register
using namespace std;
//typedef uniform_int_distribution<int> RNDI;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int Hash = 131;//13331
const int maxn = 1e5+5;
const int maxm = 100000+5;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-7;
const double pi = acos(-1);
//int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//li int f(int x){return x==par[x]?par[x]:par[x]=f(par[x]);}
//mt19937 eng(time(0));
//li int RND(int L,int R){RNDI rnd(L,R);return rnd(eng);}
li ll lowbit(ll x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
li ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res%MOD;}
li ll qmul(ll a,ll b,ll MOD=mod){return (a*b-(ll)((long double)a/MOD*b)*MOD+MOD)%MOD;}
li ll inv(ll x,ll p){return qpow(x,p-2,p);}
li ll jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
db f(db x){return x;}
li db sim(db l,db r){return (f(l)+4.*f((l+r)/2.)+f(r))*(r-l)/6.;}
db asr(db l,db r,db ans,db eps){db m=l+(r-l)/2.,L=sim(l,m),R=sim(m,r);return fabs(L+R-ans)<=15.*eps?L+R+(L+R-ans)/15.:asr(l,m,L,eps/2)+asr(m,r,R,eps/2);}
db asr(db l,db r,db eps){return asr(l,r,sim(l,r),eps);}
namespace IO
{
li ll read()
{
ll x=0,sign=1;char c=getchar();
while(c>'9'||c<'0') {if(c=='-') sign=-1;c=getchar();}
while('0'<=c&&c<='9') x=x*10+c-'0',c=getchar();
return x*sign;
}
template<typename T>
li void write(T x,char t='\n')
{
if(x<0){x=-x;putchar('-');};
static int sta[25];int top=0;
do{sta[top++]=x%10;}while(x/=10);
while(top) putchar(sta[--top]+'0');
putchar(t);
}
}
using namespace IO;
/*-------------head-------------*/
//
typedef vector<ll> VLL;
ll n,m,q,u,v,t;
priority_queue<ll> q1;
queue<ll> q2,q3;
ll get_max()
{
ll x=-inf;
if(sz(q1)) x=max(x,q1.top());
if(sz(q2)) x=max(x,q2.front());
if(sz(q3)) x=max(x,q3.front());
if(sz(q1)&&x==q1.top()) q1.pop();
else if(sz(q2)&&x==q2.front()) q2.pop();
else q3.pop();
return x;
}
li void solve()
{
m=read(),q=read(),u=read(),v=read(),t=read();
rep(i,0,n) q1.push(read());
ll delta=0;
rep(i,1,m+1)
{
ll x=get_max()+delta;
if(!(i%t)) write(x,' ');
delta+=q;
ll lef=x*u/v;ll rig=x-lef;
q2.push(lef-delta);
q3.push(rig-delta);
}
puts("");
int cnt=1;
rep(i,0,n+m)
{
ll x=get_max()+delta;
if(!(cnt++%t)) write(x,' ');
}
//puts("");
}
int main()
{
//srand(time(0));
//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//for(int QwQ=read();QwQ;QwQ--) solve();
while(~scanf("%lld",&n)) solve();
return 0;
}