求助 Div2 T3
  • 板块学术版
  • 楼主Isshiki·Iroha
  • 当前回复1
  • 已保存回复1
  • 发布时间2021/10/3 18:34
  • 上次更新2023/11/4 05:00:23
查看原帖
求助 Div2 T3
414386
Isshiki·Iroha楼主2021/10/3 18:34

0 分, AC 12,WA 4,TLE 4,虽然算法不对,但是他有 WA !!求助

#include<bits/stdc++.h>
#define ll long long
using namespace std;
namespace Mashiro {
	char buf[1<<18],*p1=buf,*p2=buf;
	inline int getc() {
		return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<18,stdin),p1==p2)?EOF:*p1++;
	}
#define getc() getchar()
	template<typename T>inline void read(T& x) {
		x=0;
		int f=1;
		char ch=getc();
		while(!isdigit(ch)) {
			if(ch=='-')f=~f+1;
			ch=getc();
		}
		while (isdigit (ch)) {
			x=(x<<3)+(x<<1)+(ch^48);
			ch=getc();
		}
		x*=f;
	}
	template <typename T,typename... Args> inline void read(T& x, Args&... args) {
		read(x);
		read(args...);
	}
	char buffer[1<<18];
	int p11=-1;
	const int p22=(1<<18)-1;
	inline void flush() {
		fwrite(buffer,1,p11+1,stdout),p11=-1;
	}
	inline void putc(const char &x) {
		if (p11==p22) flush();
		buffer[++p11]=x;
	}
	template<typename T>inline void write(T x) {
		static int buf[40],top=0;
		if(x<0)putc('-'),x=~x+1;
		while(x)buf[++top]=x%10,x/=10;
		if(top==0)buf[++top]=0;
		while (top) putc(buf[top--]^48);
		putc(' ');
		flush();
	}
	template <typename T,typename... Args> inline void write(T x, Args... args) {
		write(x);
		write(args...);
	}
}
using namespace Mashiro;
const int maxn=3e6+10;
int n,q;
ll a[maxn];
int main() {
	read(n,q);
	for(int i(1),t; i<=n; ++i) {
		read(a[i]);
	}
	sort(a+1,a+1+n,greater<ll>());
	for(ll i(1),u,nxt,nxt1,step=0; i<=q; ++i) {
		read(u);
		step=0;
		ll temp=lower_bound(a+1,a+1+n,u,greater<ll>())-a;
		if(temp==n+1||a[temp]==u)goto LLL;
		while(true) {
			nxt=lower_bound(a+1,a+1+n,u,greater<ll>())-a;
			if(nxt==n+1)break;
			nxt=a[nxt];
			nxt1=upper_bound(a+1,a+1+n,nxt,greater<ll>())-a;
			if(nxt1==n+1){
				if(nxt<=u-nxt)break;		
				++step;
				break;
			}
			else nxt1=a[nxt1];
			if(nxt-nxt1<=u-nxt)break;
			++step;
			u=nxt-(u-nxt);
		}
		LLL:;
		write(step);
		putc('\n');
	}
	return 0;
}

2021/10/3 18:34
加载中...