QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#60675#3853. Lines in a gridSorting#WA 753ms599064kbC++2.5kb2022-11-06 06:43:542022-11-06 06:43:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-06 06:43:57]
  • 评测
  • 测评结果:WA
  • 用时:753ms
  • 内存:599064kb
  • [2022-11-06 06:43:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < int , int > pii ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MAXN = 1e7 + 7 ;
const int MOD = 1000003 ;


bool comp[ MAXN ] ;
vector < int > divs[ MAXN ] ;

int eu[ MAXN ] ;

ll sm_xy[ MAXN ] , sm_x[ MAXN ] , sm_y[ MAXN ] ;
ll cnt[ MAXN ] ;

void solve ( ) {
    for ( int i = 1 ; i < MAXN ; ++ i ) {
        eu[ i ] = 1 ;
    }
    for ( int i = 2 ; i < MAXN ; ++ i ) {
        if ( comp[ i ] == true ) { continue ; }
        for ( int j = i ; j < MAXN ; j += i ) {
            if ( i != j ) { 
                comp[ j ] = true ;
            }
            int ctr = 0 ;
            int dummy = j ;
            while ( ( dummy % i ) == 0 ) {
                if ( ctr == 0 ) {
                    eu[ j ] = eu[ j ] * ( i - 1 ) ;
                }
                else {
                    eu[ j ] = eu[ j ] * i ;
                }
                ++ ctr ;
                dummy /= i ;
            }
        }
    }
    for ( int i = 1 ; i < MAXN ; ++ i ) {
        sm_x[ i ] = sm_x[ i - 1 ] + 2LL * i * eu[ i ] ;
        if ( i == 1 ) { -- sm_x[ i ] ; }
        
        sm_x[ i ] %= MOD ;
        if ( i > 1 ) {
            sm_y[ i ] = sm_y[ i - 1 ] + 2 * eu[ i ] ;
            if ( i == 1 ) { -- sm_y[ i ] ; }
        }
        else {
            sm_y[ i ] = 1 ;
        }
        ll aux = 1LL * i * i ;
        aux %= MOD ;
        aux = ( aux * eu[ i ] ) % MOD ;
        sm_xy[ i ] = sm_xy[ i - 1 ] + aux ;

        cnt[ i ] = ( cnt[ i - 1 ] + 2 * eu[ i ] ) % MOD ;
        if ( i == 1 ) { -- cnt[ i ] ; }
    }
    int q ; cin >> q ;
    while ( q -- ) {
        int x ; cin >> x ;
        if ( x == 1 ) { cout << "0\n" ; }
        else {
            int mid = ( x / 2 ) ;
            ll ans = ( cnt[ x - 1 ] * x * x ) % MOD - ( sm_y[ x - 1 ] * x ) % MOD - ( sm_x[ x - 1 ] * x ) % MOD + sm_xy[ x - 1 ] ;
            ans = ( ans + 10 * MOD ) % MOD ;
            
            ll sub = ( cnt[ mid ] * x * x ) % MOD - ( 2LL * sm_y[ mid ] * x ) % MOD - ( 2LL * sm_x[ mid ] * x ) % MOD + 4LL * sm_xy[ mid ] ;
            sub = ( sub + 10 * MOD ) % MOD ;
            ans = ( ans - sub + MOD ) % MOD ;
            ans *= 2 ;
            ans += 2 * x ;
            ans %= MOD ;
            cout << ans << "\n" ;
        }
    }
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; // cin >> t ; 
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 753ms
memory: 599064kb

input:

10
1 2 3 4 5 6 7 8 9 10

output:

0
6
20
78
200
474
844
1642
2716
4026

result:

wrong answer 4th lines differ - expected: '62', found: '78'