QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#616189 | #9250. Max GCD | propane | AC ✓ | 2257ms | 497436kb | C++20 | 2.4kb | 2024-10-05 23:19:26 | 2024-10-05 23:19:26 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<numeric>
#include<functional>
#include<array>
#include<cmath>
using namespace std;
using LL = long long;
// int tr[150005];
// int lowbit(int x){
// return x & -x;
// }
// void modify(int x, int v){
// while(x <= 150'000){
// tr[x] = max(tr[x], v);
// x += lowbit(x);
// }
// }
// int query_max(int x){
// int ans = 0;
// while(x){
// ans = max(ans, tr[x]);
// x -= lowbit(x);
// }
// return ans;
// }
int mx[150005], mx1[150005];
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
const int N = 1e6;
int n, m;
cin >> n >> m;
vector<vector<int> > pos(N + 1);
for(int i = 1; i <= n; i++){
int t;
cin >> t;
for(int j = 1; j * j <= t; j++){
if (t % j == 0){
pos[j].push_back(i);
if (j * j != t){
pos[t / j].push_back(i);
}
}
}
}
vector<vector<pair<int, int> > > seg(n + 1);
for(int i = 1; i <= N; i++){
if (!pos[i].empty()){
for(int j = 0; j + 1 < pos[i].size(); j++){
int a = pos[i][j], b = pos[i][j + 1];
int k = lower_bound(pos[i].begin(), pos[i].end(), 2 * b - a) - pos[i].begin();
if (k != pos[i].size()) seg[a].push_back({pos[i][k], i});
}
}
}
vector<vector<pair<int, int> > > query(n + 1);
vector<int> ans(m);
for(int i = 0; i < m; i++){
int l, r;
cin >> l >> r;
query[l].push_back({r, i});
}
const int len = sqrt(n) + 1;
for(int i = n; i >= 1; i--){
for(auto [r, val] : seg[i]){
mx[r] = max(mx[r], val);
mx1[(r + len - 1) / len] = max(mx1[(r + len - 1) / len], val);
}
for(auto [r, id] : query[i]){
for(int j = 1; ; j++){
if (j * len <= r) ans[id] = max(ans[id], mx1[j]);
else{
for(int k = (j - 1) * len + 1; k <= r; k++) ans[id] = max(ans[id], mx[k]);
break;
}
}
}
}
for(auto x : ans) cout << x << '\n';
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 26516kb
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: 2257ms
memory: 497436kb
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: 468ms
memory: 74296kb
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: 1262ms
memory: 249520kb
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: 3ms
memory: 27504kb
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: 11ms
memory: 27336kb
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: 1854ms
memory: 447732kb
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