QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735686#8980. Prime GameWzyTL 21ms13680kbC++141.8kb2024-11-11 21:16:522024-11-11 21:16:59

Judging History

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

  • [2024-11-11 21:16:59]
  • 评测
  • 测评结果:TL
  • 用时:21ms
  • 内存:13680kb
  • [2024-11-11 21:16:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef pair<char,int> PCI;
typedef pair<int,int> PII;
const int N=1000010,M=2000010;
const int mod=1e9+7;
int INF = 1e9;
int T=1;
int phi[N],st[N],primes[N],cnt,f[N];

void init(int n)
{
    phi[1] = 1;
    for (int i = 2; i <= n; i ++ )
    {
        if (!st[i])
        {
            primes[cnt ++ ] = i;
            phi[i] = i - 1;
        }
        for (int j = 0; primes[j] * i <= n; j ++ )
        {
            st[i * primes[j]] = true;
            if (i % primes[j] == 0)
            {
                phi[i * primes[j]] = phi[i] * primes[j];
                break;
            }
            phi[i * primes[j]] = phi[i] * (primes[j] - 1);
        }
    }

}

 
void solve(){
    int n;
    cin>>n;

    vector<int> a(n+10);

    for(int i=0;i<n;i++) cin>>a[i];

    map<int,vector<int>> mp;
    map<int,vector<int>> id;

    for(int i=0;i<n;i++) id[a[i]].push_back(i);

    for(int i=0;i<cnt;i++){
        for(int j=primes[i];j<=N-1;j+=primes[i]){
            if(!id.count(j)) continue;
            //cout<<j<<" "<<primes[i]<<" "<<id[j]<<endl;
            for(auto t:id[j]) mp[primes[i]].push_back(t);
        }
    }

    
    LL res=0;
    for(auto [x,y]:mp){
        sort(y.begin(),y.end());

        //cout<<x<<endl;
        //for(auto t:y) cout<<t<<" ";
        //cout<<endl;

        for(int i=0;i<y.size();i++){
            //cout<<x<<" "<<y[i]<<endl;
            if(i==y.size()-1) res+=(n-y[i])*(y[i]+1);
            else res+=(y[i+1]-y[i])*(y[i]+1);
        }
    } 


    cout<<res<<endl;
    

}

    
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //int T=1;
    //cin>>T;
    init(N-1);
    while(T--) solve();
 
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 16ms
memory: 13680kb

input:

10
99 62 10 47 53 9 83 33 15 24

output:

248

result:

ok single line: '248'

Test #2:

score: 0
Accepted
time: 21ms
memory: 11728kb

input:

10
6 7 5 5 4 9 9 1 8 12

output:

134

result:

ok single line: '134'

Test #3:

score: 0
Accepted
time: 13ms
memory: 11696kb

input:

10
99 62 10 47 53 9 83 33 15 24

output:

248

result:

ok single line: '248'

Test #4:

score: 0
Accepted
time: 19ms
memory: 11984kb

input:

10
692137 743219 52652 45276 492360 972264 988496 117515 917868 423315

output:

521

result:

ok single line: '521'

Test #5:

score: 0
Accepted
time: 19ms
memory: 11736kb

input:

100
408775 951905 198113 227169 170826 717434 172837 379198 720110 733849 256909 997639 834222 642949 317137 409227 410206 641528 625980 937295 557730 566754 910637 716940 949428 513251 236121 195566 241377 442709 617863 89943 809036 620607 976274 444954 341290 780899 673131 169536 855557 140849 834...

output:

255236

result:

ok single line: '255236'

Test #6:

score: 0
Accepted
time: 19ms
memory: 11776kb

input:

100
620478 109788 646916 312450 22667 609293 640239 655905 216968 843038 852594 133249 544178 720291 37881 435654 196271 976771 719580 494391 767626 423169 168736 199494 80683 744612 304689 133336 547615 244143 920884 220033 820152 494269 954687 660735 882144 978008 694034 221928 706590 479076 43374...

output:

245996

result:

ok single line: '245996'

Test #7:

score: -100
Time Limit Exceeded

input:

1000000
709877 145493 170549 915888 2504 680394 758139 24665 365499 242644 535590 994789 297247 518365 834337 852392 945750 480961 126953 485671 11673 262033 473744 199902 743475 91856 394619 779195 616388 60537 756645 570144 510464 285494 932570 298148 627373 110058 469501 686867 559208 82153 90754...

output:


result: