社区讨论

奇怪的RE

学术版参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@lo8ejgqo
此快照首次捕获于
2023/10/27 17:19
2 年前
此快照最后确认于
2023/11/02 11:13
2 年前
查看原帖
RT,题目:abc238_g。空间限制:1G
今天模拟赛出了这题,我写了个分块部分分,但是赛后发现交上去 RE 了,但是大样例本题也 1min 内跑过了,AT 上虽然 TLE 了,但是剩下的也是 AC。
现在毫无头绪,特来求助谷内语法大佬帮忙看看到底是什么问题导致 RE。
AT 的警告给出的线索是:
CPP
Main.cpp: In function ‘int main()’:
Main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         scanf("%d%d",&n,&q);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:40:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |                 scanf("%d",&a[i]);
      |                 ~~~~~^~~~~~~~~~~~
Main.cpp:60:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |                 scanf("%d%d",&l,&r);
      |                 ~~~~~^~~~~~~~~~~~~~
Main.cpp: In function ‘void ycl()’:
Main.cpp:19:16: warning: iteration 1000008 invokes undefined behavior [-Waggressive-loop-optimizations]
   19 |         if(st[i]==false){
      |            ~~~~^
Main.cpp:18:18: note: within this loop
   18 |     for(int i=2;i<=M;i++){
      |  
我的代码
CPP
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<set>
using namespace std;
const int N=2e5+10;
const int M=1e6+10;
int n,q,len,maxn,pi[800001],minp[M],tot,a[N];
bool st[M];
void ycl(){
    for(int i=2;i<=1000000;i++){
        if(st[i]==false){
            pi[++tot]=i;
            minp[i]=tot;
        }
        for(int j=1;pi[j]<=1000000/i;j++){
            st[i*pi[j]]=true;
            if(minp[i*pi[j]]==0){
            	minp[i*pi[j]]=j;
			}
            if(i%pi[j]==0){
                break;
            } 
        }
    }
}
int blo[451][800001],qry[800001];
signed main(){
	scanf("%d%d",&n,&q);
	ycl();
	len=ceil((double)sqrt(n));
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		maxn=max(maxn,a[i]);
		int bn=(i-1)/len+1,tem=a[i];
		while(tem!=1){
			int p=minp[tem],cnt=0;
			while(tem%pi[p]==0){
				tem/=pi[p];
				cnt++;
			}
			blo[bn][p]+=cnt;
		}
	}
	int lim=lower_bound(pi+1,pi+tot+1,maxn)-pi; 
	for(int i=1;i<=(n-1)/len+1;i++){
		for(int j=1;j<=lim;j++){
			blo[i][j]+=blo[i-1][j];
		}
	}
	int l,r;
	while(q--){
		scanf("%d%d",&l,&r);
		int bl=(l-1)/len+1,br=(r-1)/len+1,fl=0;
		if(l!=(bl-1)*len+1){
			bl++;
		}
		if(r!=br*len){
			br--;
		}
		for(int i=1;i<=lim;i++){
			qry[i]=0;
		}
		if(bl>br){
			for(int i=l;i<=r;i++){
				int tem=a[i];
				while(tem!=1){
					int p=minp[tem],cnt=0;
					while(tem%pi[p]==0){
						tem/=pi[p];
						cnt++;
					}
					qry[p]+=cnt;
				}
			}
		}
		else{
			for(int j=1;j<=lim;j++){
				qry[j]+=blo[br][j]-blo[bl-1][j];
			}
			if((l-1)/len+1!=bl){
				for(int i=l;i<=(bl-1)*len;i++){
					int tem=a[i];
					while(tem!=1){
						int p=minp[tem],cnt=0;
						while(tem%pi[p]==0){
							tem/=pi[p];
							cnt++;
						}
						qry[p]+=cnt;
					}
				}
			}
			if((r-1)/len+1!=br){
				for(int i=br*len+1;i<=r;i++){
					int tem=a[i];
					while(tem!=1){
						int p=minp[tem],cnt=0;
						while(tem%pi[p]==0){
							tem/=pi[p];
							cnt++;
						}
						qry[p]+=cnt;
					}
				}
			}
		}
		for(int i=1;i<=lim;i++){
			if(qry[i]%3!=0){
				putchar('N'),putchar('o');
				fl=1;
				break;
			}
		}
		if(fl==0){
			putchar('Y'),putchar('e'),putchar('s');
		}
		putchar('\n');
	}
}

回复

2 条回复,欢迎继续交流。

正在加载回复...