Submission #16876018


Source Code Expand

/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

int step(int a, int m) {
    return (a*a)%m;
}

/* At less than m elements the seq repeats. */
void solve() {
    cini(n);
    cini(x);
    cini(m);

    vi first(m, -1);
    vi pre(2*m);

    int ans=0;
    for(int i=1; i<=n; i++) {
        if(first[x]>=0) {
            int loopsize=i-first[x];
            int loopsum=pre[i-1]-pre[first[x]-1];

            int loops=(n-i)/loopsize;
            ans+=loops*loopsum;
            i+=loops*loopsize;
            for(int j=0; j<first.size(); j++)
                first[j]=-1;
        }

        if(i<pre.size()) {
            pre[i]=pre[i-1]+x;
            first[x]=i;
        }

        ans+=x;
        x=step(x,m);
    }
    cout<<ans<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS

Submission Info

Submission Time
Task E - Sequence Sum
User spookywooky
Language C++ (GCC 9.2.1)
Score 500
Code Size 1729 Byte
Status AC
Exec Time 16 ms
Memory 5556 KiB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:61:27: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   61 |             for(int j=0; j<first.size(); j++)
      |                          ~^~~~~~~~~~~~~
./Main.cpp:65:13: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   65 |         if(i<pre.size()) {
      |            ~^~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, max_01.txt, max_02.txt, max_03.txt, max_11.txt, max_12.txt, max_13.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 7 ms 3476 KiB
hand_02.txt AC 3 ms 3512 KiB
hand_03.txt AC 5 ms 5384 KiB
hand_04.txt AC 7 ms 5512 KiB
hand_05.txt AC 10 ms 5528 KiB
max_01.txt AC 16 ms 5556 KiB
max_02.txt AC 14 ms 5556 KiB
max_03.txt AC 8 ms 5440 KiB
max_11.txt AC 6 ms 5372 KiB
max_12.txt AC 6 ms 5508 KiB
max_13.txt AC 7 ms 5552 KiB
random_01.txt AC 4 ms 3656 KiB
random_02.txt AC 5 ms 4204 KiB
random_03.txt AC 5 ms 5176 KiB
random_04.txt AC 3 ms 3716 KiB
random_05.txt AC 2 ms 3584 KiB
random_06.txt AC 4 ms 3840 KiB
random_07.txt AC 4 ms 4920 KiB
random_08.txt AC 5 ms 5112 KiB
random_09.txt AC 3 ms 4132 KiB
random_10.txt AC 4 ms 4652 KiB
sample_01.txt AC 4 ms 3588 KiB
sample_02.txt AC 4 ms 3596 KiB
sample_03.txt AC 7 ms 5448 KiB