QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#771767 | #9250. Max GCD | AzusidNya | WA | 1268ms | 219084kb | C++17 | 2.2kb | 2024-11-22 15:33:02 | 2024-11-22 15:33:02 |
Judging History
answer
#include<bits/stdc++.h>
// #define int long long
#define eb emplace_back
#define mp make_pair
// #define DEBUG
using namespace std;
using pii = pair<int, int>;
using piii = pair<int, pii>;
using piiii = pair<pii, pii>;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned int;
const int P = 998244353;const i64 inf = 0x3f3f3f3f3f3f3f3f;
namespace BIT{
#define lowbit(u) (u & -u)
int add(vector<int> &tr, int u, int v){
int n = tr.size() - 1;
u ++;
for(; u <= n; u += lowbit(u))
tr[u] = max(tr[u], v);
return 0;
}
int ask(vector<int> &tr, int u){
int ret = 0;
u ++;
for(; u; u -= lowbit(u)){
ret = max(ret, tr[u]);
}
return ret;
}
} using namespace BIT;
namespace azus{
int n, q;
vector<int> pos[1000005];
vector<int> fac[1000005];
vector<pii> cq[200005];
// unordered_set<int> s[200005];
int ml[200005];
vector<int> tr;
vector<pii> que[200005];
int ans[200005];
int main(){
cin >> n >> q;
for(int i = 1; i <= n; i ++){
int x; cin >> x; pos[x].eb(i);
}
for(int i = 1; i <= 1000000; i ++){
for(int j = i; j <= 1000000; j += i){
for(int k : pos[j])
fac[i].eb(k);
}
sort(fac[i].begin(), fac[i].end());
}
for(int i = 1000000; i >= 1; i --){
if(fac[i].size() < 3) continue;
int w = fac[i].size();
int r = w;
for(int l = w - 3; l >= 0; l --){
int m = l + 1;
int len = fac[i][m] - fac[i][l];
int cw = fac[i][m] + len;
while(fac[i][r - 1] >= cw && r - 1 > m) r --;
if(r == w || fac[i][r] < cw) continue;
if(ml[fac[i][r]] > fac[i][l]){
continue;
}
cq[fac[i][r]].eb(mp(fac[i][l], i));
ml[fac[i][r]] = max(ml[i], fac[i][l]);
}
}
tr.assign(n + 5, 0);
for(int i = 1; i <= q; i ++){
int l, r; cin >> l >> r;
que[r].eb(mp(l, i));
}
for(int i = 1; i <= n; i ++){
for(auto [l, vl] : cq[i]){
add(tr, (n - l + 1), vl);
}
for(auto [l, id] : que[i]){
ans[id] = ask(tr, n - l + 1);
}
}
for(int i = 1; i <= q; i ++){
cout << ans[i] << "\n";
}
return 0;
}
}
signed main(){
#ifndef DEBUG
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#endif
int T = 1;
while(T --)
azus::main();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 42ms
memory: 60656kb
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: -100
Wrong Answer
time: 1268ms
memory: 219084kb
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:
wrong answer 14838th words differ - expected: '55440', found: '0'