結果

問題 No.2758 RDQ
コンテスト
ユーザー 👑 tails
提出日時 2024-05-17 22:23:40
言語 C90
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,754 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 132 ms
コンパイル使用メモリ 29,040 KB
最終ジャッジ日時 2026-02-24 01:19:42
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c: In function 'f0':
main.c:22:14: error: expected ';' before 'i'
   22 |         reps(i,1,100001){
      |              ^
main.c:8:35: note: in definition of macro 'reps'
    8 | #define reps(v,s,e) for(typeof(e) v=s;v<e;++v)
      |                                   ^
main.c:22:14: error: 'i' undeclared (first use in this function)
   22 |         reps(i,1,100001){
      |              ^
main.c:8:39: note: in definition of macro 'reps'
    8 | #define reps(v,s,e) for(typeof(e) v=s;v<e;++v)
      |                                       ^
main.c:22:14: note: each undeclared identifier is reported only once for each function it appears in
   22 |         reps(i,1,100001){
      |              ^
main.c:8:39: note: in definition of macro 'reps'
    8 | #define reps(v,s,e) for(typeof(e) v=s;v<e;++v)
      |                                       ^
main.c:23:23: error: expected ';' before 'j'
   23 |                 repst(j,i,100001,i){
      |                       ^
main.c:9:38: note: in definition of macro 'repst'
    9 | #define repst(v,s,e,t) for(typeof(e) v=s;v<e;v+=t)
      |                                      ^
main.c:23:23: error: 'j' undeclared (first use in this function)
   23 |                 repst(j,i,100001,i){
      |                       ^
main.c:9:42: note: in definition of macro 'repst'
    9 | #define repst(v,s,e,t) for(typeof(e) v=s;v<e;v+=t)
      |                                          ^
main.c: In function 'sort_aux':
main.c:31:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   31 |         for(int i=0;i<256;++i){
      |         ^~~
main.c:31:9: note: use option '-std=c99', '-std=gnu99', '-std=c11' or '-std=gnu11' to compile your code
main.c:34:17: error: redefinition of 'i'
   34 |         for(int i=0;i<n;++i){
      |                 ^
main.c:31:17: note: previous definition of 'i' with type 'int'
   31 |         for(int i=0;i<256;++i){
      |                 ^
main.c:34:9: error: 'for' loop initial dec

ソースコード

diff #
raw source code

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) {unsigned _z=v,_n=0;ulong _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(ulong*)wp=_d;wp+=_n;}
#define rep(v,e) for(typeof(e) v=0;v<e;++v)
#define reps(v,s,e) for(typeof(e) v=s;v<e;++v)
#define repst(v,s,e,t) for(typeof(e) v=s;v<e;v+=t)

typedef unsigned long ulong;

char wbuf[1<<25];
int ds[100001][128],dn[100001];
int a[50000];
struct{int l,r,k;} qs[50000];
int qi[100000];
int z[50000];
int c[100001];

void f0(){
	reps(i,1,100001){
		repst(j,i,100001,i){
			ds[j][dn[j]++]=i;
		}
	}
}

void sort_aux(int*a,int*b,int n,int p){
	int c[256];
	for(int i=0;i<256;++i){
		c[i]=0;
	}
	for(int i=0;i<n;++i){
		int u=a[i];
		unsigned v=u&1?qs[u>>1].r<<1|1:qs[u>>1].l<<1|0;
		++c[v>>(p<<3)&255];
	}
	int t=0;
	for(int i=0;i<256;++i){
		int u=c[i];
		c[i]=t;
		t+=u;
	}
	for(int i=0;i<n;++i){
		int u=a[i];
		unsigned v=u&1?qs[u>>1].r<<1|1:qs[u>>1].l<<1|0;
		b[c[v>>(p<<3)&255]++]=u;
	}
}

void sort(int*a,int n){
	int*b=wbuf;
	sort_aux(a,b,n,0);
	sort_aux(b,a,n,1);
	sort_aux(a,b,n,2);
	sort_aux(b,a,n,3);
}

int main(){
	f0();
	rd_init();
	int n=rd();
	int q=rd();
	rep(i,n){
		a[i]=rd();
	}
	rep(j,q){
		qs[j].l=rd()-1;
		qs[j].r=rd()-1;
		qs[j].k=rd();
	}
	rep(j,q*2){
		qi[j]=j;
	}
	sort(qi,q*2);
	int d=0;
	rep(i,n){
		while(d<n*2&&!(qi[d]&1)&&qs[qi[d]>>1].l==i){
			z[qi[d]>>1]=-c[qs[qi[d]>>1].k];
			++d;
		}
		rep(b,dn[a[i]]){
			c[ds[a[i]][b]]+=1;
		}
		while(d<n*2&&(qi[d]&1)&&qs[qi[d]>>1].r==i){
			z[qi[d]>>1]+=c[qs[qi[d]>>1].k];
			++d;
		}
	}
	char*wp=wbuf;
	rep(j,q){
		wt(z[j]);
		*wp++='\n';
	}
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0