QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#648240#6627. Line TownRainSkyCompile Error//C++141.5kb2024-10-17 17:49:562024-10-17 17:49:56

Judging History

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

  • [2024-10-17 17:49:56]
  • 评测
  • [2024-10-17 17:49:56]
  • 提交

answer

#include <cstdio>
#include <algorithm>
using namespace std;
inline int read() {
	int x = 0, f = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
	return x * f;
}
typedef long long ll;
const int N=1000003;
const ll INF=0x3f3f3f3f3f3f3f3f;
typedef pair<int,int> pii;
int n,a[N];
pii b[N];
ll f[2][2][2],g[2][2][2];
void chmn(ll &x,ll v){if(x>v) x=v;}
int tr[N];
int qry(int x){
	int res=0;
	for(int i=x;i;i^=(i&-i)) res+=tr[i];
	return res;
}
void upd(int x){
	for(int i=x;i<=n;i+=(i&-i)) ++tr[i];
}
int main(){
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	for(int i=1;i<=n;++i) if(i&1) a[i]=-a[i];
	for(int i=1;i<=n;++i) b[i]=pii(abs(a[i]),i);
	sort(b+1,b+n+1);
	for(int t=0;t<2;++t)
		for(int x=0;x<2;++x)
			for(int y=0;y<2;++y) f[t][x][y]=INF;
	f[1][0][0]=f[0][1][1]=0;
	for(int i=1;i<=n;++i){
		int p=b[i].second;
		int pre=qry(p),suf=i-1-qry(p);
		upd(p);
		bool c=(a[p]<0);
		for(int t=0;t<2;++t)
			for(int x=0;x<2;++x)
				for(int y=0;y<2;++y)
					g[t][x][y]=f[t][x][y],f[t][x][y]=INF;
		for(int t=0;t<2;++t)
			for(int x=0;x<2;++x)
				for(int y=0;y<2;++y){
					if(g[t][x][y]==INF) continue;
					if(c==x) chmn(f[t^1][x^1][y],g[t][x][y]+pre);
					if(c==y) chmn(f[t][x][y^1],g[t][x][y]+suf);
				}
	}
	ll res=INF;
	for(int x=0;x<2;++x)
		for(int y=0;y<2;++y) chmn(res,f[0][x][y]);
	if(res==INF) puts("-1");
	else printf("%lld\n",res);
	return 0;
}

Details

answer.code: In function ‘int read()’:
answer.code:6:17: error: ‘isdigit’ was not declared in this scope
    6 |         for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
      |                 ^~~~~~~
answer.code:7:16: error: ‘isdigit’ was not declared in this scope
    7 |         for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
      |                ^~~~~~~