QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#587699#9250. Max GCDShiinaMahiruAC ✓919ms692180kbC++172.8kb2024-09-24 21:07:172024-09-24 21:07:22

Judging History

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

  • [2024-09-24 21:07:22]
  • 评测
  • 测评结果:AC
  • 用时:919ms
  • 内存:692180kb
  • [2024-09-24 21:07:17]
  • 提交

answer

// #pragma GCC optimize(2)
#include<bits/stdc++.h>
#define endl '\n'
#define lowbits(x) ((x)&((-x)))
#define INF 0x3f3f3f3f
#define uu __int128
#define PI acos(-1)
#define ls k<<1
#define rs k<<1|1
using namespace std;
typedef  long long ll;
typedef  unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PII;
constexpr int N=150000+10, M=1e6+10;
constexpr int mod=998244353;
constexpr double eps=1e-9;
int nx[] = {0, 0, 1, -1}, ny[] = {1, -1, 0, 0};


int n,m;
int a[N];
vector<P> dai[N];
int pre[M], cur[M];


vector<P> g[N], q[N];
constexpr int B = 400;
int id[N], L[N], R[N];
vector<int> SUM;
vector<vector<int>> sum;
void init(){
    for(int i=1; i<=n; ++i){
        id[i] = (i-1) / B + 1;
    }
    for(int i=1; i<=id[n]; ++i){
        L[i] = (i-1) * B + 1;
        R[i] = min(n, i * B);
    }
    SUM.resize(id[n]+10);
    sum.resize(id[n]+10);
    for(int i=0; i<=id[n]; ++i)sum[i].resize(R[i] - L[i] + 10);
}

void update(int y, int w){
    sum[id[y]][y - L[id[y]] + 1] = max(sum[id[y]][y - L[id[y]] + 1], w);
    SUM[id[y]] = max(SUM[id[y]], w);
}

int query(int x){
    int res = 0;
    for(int i=1; i<id[x]; ++i)res = max(res, SUM[i]);
    for(int i=L[id[x]]; i<=x; ++i)res = max(res, sum[id[x]][i - L[id[x]] + 1]);
    return res;
}


void solve(){
    cin >> n >> m;
    init();
    auto add = [&](int x, int pos){
        
        if(pre[x]){
            if(pos * 2 - pre[x] <= n)
            dai[pos * 2 - pre[x]].push_back({pre[x], x});
			// cout << pre[x] << ' ' << pos * 2 - pre[x] << ' ' << x << endl;
        }
        pre[x] = pos;
        if(cur[x]){
			g[cur[x]].push_back({pos, x});
			cur[x] = 0;
			// cout << cur[x] << ' ' << pos << ' ' << x << endl;
		}
    };
    for(int i=1; i<=n; ++i){
        cin >> a[i];
		for(auto [l, y] : dai[i]){
			cur[y] = max(cur[y], l);
		}
        dai[i].clear();
        for(int j=1; j*j<=a[i]; ++j){
            if(a[i] % j == 0){
                int k = a[i] / j;
                add(j, i);
                if(j != k)
                add(k, i);
            }
        }
    }
    // for(int i=1; i<=n; ++i){
    //     if(g[i].size()){
    //         for(auto [y, w] : g[i])cout << i << ' ' << y << ' ' << w << endl;
    //     }
    // }
    for(int i=1; i<=m; ++i){
        int l,r;
        cin >> l >> r;
        q[l].push_back({r, i});
    }
    vector<int> res(m+1);
    for(int i=n; i>=1; --i){
        for(auto [y, w] : g[i]){
            update(y, w);
        }
        for(auto [r, id] : q[i]){
            res[id] = query(r);
        }
    }
    for(int i=1; i<=m; ++i)cout << res[i] << endl;



}


signed main()
{   
    ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
    int t = 1;
    // cout << fixed << setprecision(9)
    // cin >> t;
    while(t--)solve();
    return 0;

}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 17952kb

input:

8 8
8 24 4 6 6 7 3 3
1 5
2 6
3 7
5 8
4 8
1 3
2 5
3 8

output:

4
2
3
1
3
4
2
3

result:

ok 8 tokens

Test #2:

score: 0
Accepted
time: 919ms
memory: 692180kb

input:

150000 100000
982800 554400 665280 982800 997920 720720 786240 831600 997920 982800 786240 982800 942480 831600 887040 665280 831600 960960 786240 982800 786240 942480 665280 831600 942480 665280 982800 960960 960960 997920 720720 960960 960960 665280 982800 665280 982800 942480 786240 997920 554400...

output:

997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920...

result:

ok 100000 tokens

Test #3:

score: 0
Accepted
time: 384ms
memory: 60524kb

input:

150000 100000
716844 340255 836453 422971 389959 56166 837543 724949 336855 860372 579302 812222 849774 845846 999555 136871 624002 100905 529143 187215 582397 95964 363772 534762 258007 132867 753342 300681 770692 654005 397230 267857 21953 347450 248776 397101 768172 868404 612257 885884 270063 45...

output:

962054
997805
890994
997805
302526
997805
997805
977481
977481
962054
997805
977481
187969
962054
389779
753782
385422
267290
299894
219398
73821
400069
997805
722583
58309
962054
977481
997805
963049
997805
413562
994191
997805
426490
997805
962054
962054
753782
484075
997805
994191
299879
761650
7...

result:

ok 100000 tokens

Test #4:

score: 0
Accepted
time: 678ms
memory: 252532kb

input:

150000 100000
956340 841620 591480 585312 733440 381480 918540 326160 154980 826272 873054 789264 642330 261576 504450 328500 462720 872040 463590 387720 240768 31320 774090 997668 380250 496692 858420 294060 286000 896448 987690 780216 945744 159432 825804 776880 946110 673530 583596 547400 335880 ...

output:

999999
999999
957720
999999
999460
952770
999432
999999
999999
999999
999999
999999
999999
999999
991380
999960
999999
999999
384480
999999
999432
999999
999999
994410
999999
999120
999999
999680
999460
999999
997704
151470
999999
999999
999999
999960
232190
999804
999960
999936
999460
998424
999999...

result:

ok 100000 tokens

Test #5:

score: 0
Accepted
time: 0ms
memory: 20760kb

input:

200 100
489060 226800 933660 924000 939120 291060 702240 913920 979440 778050 505440 611520 837900 662400 207900 829920 814320 194040 991200 463320 638400 288288 544320 609840 425040 855360 859320 327600 772200 918000 502320 693000 841500 502320 617760 371280 823680 900900 757680 823680 710640 59976...

output:

207900
823680
823680
131670
823680
19950
137700
55440
823680
823680
823680
48600
207900
207900
823680
823680
137700
231840
5796
1260
823680
231840
111384
540960
131670
823680
823680
207900
27720
823680
205920
231840
32760
207900
231840
207900
39312
207900
0
207900
151200
823680
31680
231840
207900
2...

result:

ok 100 tokens

Test #6:

score: 0
Accepted
time: 0ms
memory: 18980kb

input:

200 100
571200 926640 748800 936000 561600 601920 820800 571200 423360 514800 428400 995904 899640 899640 982080 993600 730800 803880 914760 687960 556920 458640 950400 884520 686400 873180 514800 411840 463680 327600 811440 875160 974400 485100 529200 963900 491400 785400 952560 611520 823680 68544...

output:

963900
963900
81900
237600
792000
85680
71400
458640
229320
212520
963900
4620
317520
52920
963900
383040
35700
52920
57120
383040
51480
914760
137280
963900
766080
21420
237600
85680
32760
317520
914760
914760
914760
191520
963900
154440
963900
963900
237600
963900
237600
766080
33600
963900
914760...

result:

ok 100 tokens

Test #7:

score: 0
Accepted
time: 809ms
memory: 443484kb

input:

150000 100000
669240 987000 959400 760320 619080 715680 651000 297000 611520 816480 529200 936000 660660 856800 993720 678300 316800 951048 716040 748800 619080 939120 733590 974610 382200 870240 750750 423360 846300 750120 907200 355320 844800 582120 547200 986580 792792 291060 989520 696150 546000...

output:

999600
999600
999600
999600
999600
992160
999600
999600
999600
999600
999600
999600
999600
995904
997920
999600
999600
999600
999600
999600
999600
999600
999180
999600
999600
999600
999600
999180
999600
999600
999600
999600
999600
999600
999600
999600
999600
999600
999600
999600
999600
999600
999600...

result:

ok 100000 tokens

Extra Test:

score: 0
Extra Test Passed