提出 #15672029


ソースコード 拡げる

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX=500005;

struct qry{
    ll order;
    int l,r,i;
    bool operator < (const qry &a) const{
        return order<a.order;
    }
} qr[MX];
int a[MX],fr[MX],ans[MX];

inline ll hilbert(int x,int y)
{
    static const ll co[8][4]={
        {0,3,1,2},{3,0,2,1},{1,2,0,3},{2,1,3,0},
        {0,1,3,2},{3,2,0,1},{1,0,2,3},{2,3,1,0}
    };
    static const int rot[8][4]={
        {4,7,0,0},{5,6,1,1},{2,2,5,6},{3,3,4,7},
        {0,4,3,4},{1,5,2,5},{6,1,6,2},{7,0,7,3}
    };
    static const int pos[2][2]={{3,1},{2,0}};
    ll o=0;
    int k=20,r=0;
    while(k){
        ll d=1ll<<(k-1);
        ll pw=1ll<<(k+k-2);
        int p=pos[x<d][y<d];
        o+=co[r][p]*pw,r=rot[r][p];
        x-=(x<d)?0:d,y-=(y<d)?0:d,k--;
    }
    return o;
}

int main(){
    int n,q,x,y,l,r;
    scanf("%d %d",&n,&q);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    for(int i=0;i<q;i++){
        scanf("%d %d",&l,&r);
        qr[i].l=l-1,qr[i].r=r-1;
        qr[i].i=i,qr[i].order=hilbert(l-1,r-1);
    }
    sort(qr,qr+q);
    x=y=0,fr[a[0]]=1;
    int s=1;
    for(int i=0;i<q;i++){
        l=qr[i].l,r=qr[i].r;
        while(x<l){
            fr[a[x]]--;
            if(fr[a[x]]==0) s--;
            x++;
        }
        while(x>l){
            x--;
            fr[a[x]]++;
            if(fr[a[x]]==1) s++;
        }
        while(y<r){
            y++;
            fr[a[y]]++;
            if(fr[a[y]]==1) s++;
        }
        while(y>r){
            fr[a[y]]--;
            if(fr[a[y]]==0) s--;
            y--;
        }
        ans[qr[i].i]=s;
    }
    for(int i=0;i<q;i++) printf("%d\n",ans[i]);
    return 0;
}

提出情報

提出日時
問題 F - Range Set Query
ユーザ Sadman
言語 C++ (GCC 9.2.1)
得点 600
コード長 1876 Byte
結果 AC
実行時間 647 ms
メモリ 21344 KiB

コンパイルエラー

./Main.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
./Main.cpp: In function ‘int main()’:
./Main.cpp:46:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%d %d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
./Main.cpp:47:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   47 |     for(int i=0;i<n;i++) scanf("%d",&a[i]);
      |                          ~~~~~^~~~~~~~~~~~
./Main.cpp:49:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   49 |         scanf("%d %d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 2
AC × 7
セット名 テストケース
Sample sample00, sample01
All handmade02, handmade03, handmade04, handmade05, random06, sample00, sample01
ケース名 結果 実行時間 メモリ
handmade02 AC 6 ms 3728 KiB
handmade03 AC 100 ms 6900 KiB
handmade04 AC 647 ms 21344 KiB
handmade05 AC 485 ms 19356 KiB
random06 AC 613 ms 21032 KiB
sample00 AC 6 ms 3592 KiB
sample01 AC 2 ms 3776 KiB