QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#614712 | #5045. King | ANIG# | TL | 795ms | 12960kb | C++14 | 1.3kb | 2024-10-05 16:50:52 | 2024-10-05 16:50:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int t,n,mods,f[N],p[N],res,dy[N],idx;
int pows(int a,int b){
if(b==0)return 1;
int res=pows(a,b>>1);
res=res*res%mods;
if(b&1)res=res*a%mods;
return res;
}
map<int,int>q;
vector<int>g[N];
int fdl(int x,int y){
auto w=lower_bound(g[x].begin(),g[x].end(),y);
if(w==g[x].begin())return 0;
return *(--w);
}
int fdr(int x,int y){
auto w=upper_bound(g[x].begin(),g[x].end(),y);
if(w==g[x].end())return 0;
return *w;
}
void solve(int a,int b){
int k=p[b]*pows(p[a],mods-2)%mods,invk=pows(k,mods-2);
int nw=p[a],ans=2;
while(1){
nw=nw*invk%mods;
if(!q.count(nw))break;
a=fdl(q[nw],a);
if(!a)break;
ans++;
}
nw=p[b];
while(1){
nw=nw*k%mods;
if(!q.count(nw))break;
b=fdr(q[nw],b);
if(!b)break;
ans++;
}
res=max(res,ans);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>t;
while(t--){
res=0;
q.clear();idx=0;
cin>>n>>mods;
for(int i=1;i<=n;i++){
cin>>p[i];
if(!q.count(p[i]))q[p[i]]=++idx;
g[q[p[i]]].push_back(i);
}
for(int i=1;i<n;i++){
solve(i,i+1);
// cout<<i<<" "<<res<<endl;
if(i<n-1)solve(i,i+2);
// cout<<i<<" "<<res<<endl;
}
if(res<n/2.0)cout<<"-1\n";
else cout<<res<<"\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11144kb
input:
4 6 1000000007 1 1 2 4 8 16 6 1000000007 597337906 816043578 617563954 668607211 89163513 464203601 5 1000000007 2 4 5 6 8 5 1000000007 2 4 5 6 7
output:
5 -1 3 -1
result:
ok 4 number(s): "5 -1 3 -1"
Test #2:
score: 0
Accepted
time: 795ms
memory: 11328kb
input:
1000 200 495189361 193302375 262009153 248101278 250233641 303504256 426913173 23261177 206011896 214770731 286184509 492688635 207979481 282629026 450810670 41818047 359796006 445343921 241742611 249404909 41291916 392252331 125287519 92825425 162555413 371172157 420486666 270651384 309213995 11709...
output:
-1 133 -1 187 163 114 114 132 100 108 116 137 115 -1 165 115 142 165 -1 -1 108 129 -1 144 122 -1 111 146 190 159 134 -1 117 180 196 -1 -1 192 123 110 -1 106 153 103 -1 -1 103 169 -1 174 152 -1 181 113 135 -1 153 199 182 -1 177 152 177 162 -1 115 -1 -1 -1 113 128 -1 -1 -1 -1 168 167 -1 140 -1 -1 -1 1...
result:
ok 1000 numbers
Test #3:
score: 0
Accepted
time: 768ms
memory: 12628kb
input:
1000 200 949663931 479217281 320985989 765005251 6434894 250659962 96381980 929176627 859155083 837781618 895381960 276913403 206799800 594561194 451400141 287326771 230131436 499694353 149062037 769076212 249680039 876506380 680573243 672238085 235553233 593493391 524937617 832401231 490042272 4494...
output:
198 -1 -1 -1 120 -1 162 -1 101 -1 103 157 188 -1 -1 177 -1 126 114 -1 177 -1 -1 150 -1 148 140 165 -1 102 -1 192 -1 -1 -1 181 149 196 -1 -1 173 147 -1 149 -1 -1 200 -1 -1 -1 -1 -1 156 -1 114 119 199 127 123 138 169 188 146 -1 137 -1 -1 -1 121 -1 -1 121 -1 -1 -1 108 117 127 -1 127 194 -1 121 -1 -1 12...
result:
ok 1000 numbers
Test #4:
score: 0
Accepted
time: 776ms
memory: 11840kb
input:
1000 200 752331551 23573436 686888652 118880475 606109605 504896777 156156511 407092389 168008046 588489051 384747939 312334251 10179640 389706827 496937297 625716990 602916042 580060754 535624296 196865310 693079720 672788885 104900220 416739470 142969723 655913476 432092835 454858443 698545241 763...
output:
-1 179 -1 -1 126 -1 189 -1 115 -1 -1 -1 175 -1 109 -1 166 190 129 -1 -1 108 -1 135 -1 174 109 -1 183 -1 -1 -1 142 -1 105 159 163 144 -1 -1 -1 124 175 135 183 132 -1 -1 115 -1 -1 130 159 -1 -1 160 138 145 196 -1 123 163 -1 -1 181 -1 137 126 111 -1 -1 110 111 148 -1 -1 131 -1 -1 -1 101 -1 -1 -1 -1 -1 ...
result:
ok 1000 numbers
Test #5:
score: 0
Accepted
time: 768ms
memory: 12960kb
input:
1000 200 952479163 404962930 635613728 875512822 126836765 893278336 93755885 802367656 41132902 703323879 109154481 793288802 49973196 534490899 462994291 829278242 789093683 134072789 384627711 513380294 28212590 922131395 333371011 352605762 351655730 28129292 473972568 10559174 951685030 7877219...
output:
-1 -1 -1 171 -1 190 -1 -1 -1 107 -1 -1 176 -1 -1 118 -1 -1 119 -1 -1 160 -1 100 -1 -1 129 190 165 -1 -1 108 -1 -1 -1 188 167 121 189 190 113 153 -1 -1 -1 -1 142 192 186 102 108 -1 -1 -1 -1 -1 137 160 143 146 163 156 163 176 135 -1 -1 -1 -1 -1 -1 -1 -1 117 -1 -1 -1 147 166 -1 200 195 189 177 -1 143 -...
result:
ok 1000 numbers
Test #6:
score: -100
Time Limit Exceeded
input:
100 2000 146158349 19643059 687117 30976705 141997757 126939439 27291348 99640815 77869374 140943896 108863607 47555226 24332054 20814180 9774186 95917237 54599801 123926643 144812251 18602850 105663323 135089587 86540799 102680207 83257587 98590031 102391932 51059987 8865754 980981 32147720 8025236...