QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#357767#3276. 出题高手edisnimorFCompile Error//C++142.2kb2024-03-19 11:14:002024-03-19 11:14:01

Judging History

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

  • [2024-03-19 11:14:01]
  • 评测
  • [2024-03-19 11:14:00]
  • 提交

answer

#include<bits/stdc++.h>
#define il inline
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define pii pair<int, int>
#define fr first
#define sc second
#define ll long long
#define mset(f, z) memset(f, z, sizeof(f))
#define mcpy(f, g) memcpy(f, g, sizeof(g))
using namespace std;
template<typename T=ll>
il T rd(){
	T s=0; bool f=1; char c=getchar();
	while(!isdigit(c)) f^=(c=='-'), c=getchar();
	while(isdigit(c)) s=s*10+c-'0', c=getchar();
	return f? s:-s;
}
template<typename T> il void ckmx(T &x, T y){if(x<y) x=y;}
template<typename T> il void ckmn(T &x, T y){if(y<x) x=y;}
char _begin;
#define int ll
#define i128 __int128

const int N=5e5+5, M=705;

int n, m, a[N];
int Extend=2000;

il void upd(pii &x, pii y){
	if(x.fr*y.sc<y.fr*x.sc) x=y;
}

vector<pii> q[N];

int B, bid, bel[N], lp[N], rp[N];
pii mx[N], bmx[M], ans[N];

il int gcd(int a, int b){
	if(!b) return a;
	return gcd(b, a%b);
}

il void print(pii x){
	if(!x.fr){
		puts("0 1");
		return;
	}
	int gc=gcd(x.fr, x.sc);
	printf("%lld %lld\n", x.fr/gc, x.sc/gc);
}

char _end;
signed main(){
	debug("%lfMB\n", (&_end-&_begin)/1024./1024.);

	n=rd();
	for(int i=1; i<=n; i++) a[i]=rd();
	m=rd();
	for(int i=1; i<=m; i++){
		int l=rd(), r=rd();
		q[r].push_back({l, i});
	}
	B=sqrt(n);
	for(int i=1; i<=n; i++){
		bid=bel[i]=(i-1)/B+1;
		mx[i]={0, 1};
		if(!lp[bid]) lp[bid]=i, bmx[bid]={0, 1};
		rp[bid]=i;
	}
	if(n>100000){
		Extend=500;
		pii ans={0, 1};
		for(int i=1; i<=n; i++){
			for(int j=i, sum=0; j>0 && i-j+1<=Extend; j--){
				sum+=a[j];
				upd(ans, {sum*sum, i-j+1});
			}
		}
		print(ans);
		return 0;
	}
	//sweep
	for(int i=1; i<=n; i++){
		for(int j=i, sum=0; j>0 && i-j+1<=Extend; j--){
			sum+=a[j];
			pii cur={sum*sum, i-j+1};
			upd(mx[j], cur);
			upd(bmx[bel[j]], cur);
		}
		for(auto [l, id]:q[i]){
			ans[id]={0, 1};
			if(bel[l]==bel[i]) for(int j=l; j<=i; j++) upd(ans[id], mx[j]);
			else{
				for(int j=l; j<=rp[bel[l]]; j++) upd(ans[id], mx[j]);
				for(int j=bel[l]+1; j<bel[i]; j++) upd(ans[id], bmx[j]);
				for(int j=lp[bel[i]]; j<=i; j++) upd(ans[id], mx[j]);
			}
		}
	}
	for(int i=1; i<=m; i++) print(ans[i]
2 4 1);
	return 0;
}

详细

answer.code: In function ‘int main()’:
answer.code:90:26: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   90 |                 for(auto [l, id]:q[i]){
      |                          ^
answer.code:100:45: error: expected ‘)’ before numeric constant
  100 |         for(int i=1; i<=m; i++) print(ans[i]
      |                                      ~      ^
      |                                             )
  101 | 2 4 1);
      | ~