QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#750163 | #9738. Make It Divisible | Rosmontis_L# | WA | 0ms | 3848kb | C++14 | 2.7kb | 2024-11-15 13:08:44 | 2024-11-15 13:08:47 |
Judging History
answer
// #pragma GCC optimize( 2 )
#include <bitset>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <sstream>
#define rep( i , a , b ) for( int i = (a) , i##end = (b) ; i <= i##end ; ++ i )
#define per( i , a , b ) for( int i = (a) , i##end = (b) ; i >= i##end ; -- i )
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define int long long
using namespace std;
typedef long long ll;
const int P = 998244353;
const int Q = 418254373;
const int MAXN = 50006;
const int base = 131;
int n , k;
int A[MAXN];
int ps[MAXN][20];
int cmp( int a , int b ) {
return A[a] < A[b] ? a : b;
}
int qry( int l , int r ) {
int c = 31 - __builtin_clz( r - l + 1 );
return cmp( ps[l][c] , ps[r - ( 1 << c ) + 1][c] );
}
int flg = 0;
vector<int> res;
void add( int u , int v ) {
int dir = v - u;
if( dir < 0 ) dir = -dir;
if( !dir ) return;
if( !res.size() ) {
flg = 1;
for( int c = 1 ; c * c <= dir ; ++ c ) if( dir % c == 0 ) {
int cc = c - u;
if( cc >= 1 )
if( ( v + cc ) % ( u + cc ) == 0 && cc <= k ) {
res.push_back( cc );
}
if( c * c == dir ) continue;
int dc = dir / c - u;
if( dc >= 1 && ( v + dc ) % ( u + dc ) == 0 && dc <= k ) {
res.push_back( dc );
}
}
} else {
vector<int> ret;
for( int c : res ) {
if( ( v + c ) % ( u + c ) == 0 ) ret.push_back( c );
}
res = ret;
}
}
int dvd( int l , int r ) {
if( l > r ) {
return 0;
}
int m = qry( l , r );
int rtl = dvd( l , m - 1 );
int rtr = dvd( m + 1 , r );
if( rtl ) add( A[m] , A[rtl] );
if( rtr ) add( A[m] , A[rtr] );
// cout << l << ' ' << r << " : ";
// for( int x : res ) cout << x << ' '; cout << endl;
return m;
}
void solve() {
cin >> n >> k;
rep( i , 1 , n ) scanf("%lld",A + i) , ps[i][0] = i;
rep( k , 1 , 16 ) {
rep( i , 1 , n - ( 1 << k ) + 1 )
ps[i][k] = cmp( ps[i][k - 1] , ps[i + ( 1 << k - 1 )][k - 1] );
}
res.clear();
flg = 0;
dvd( 1 , n );
if( !flg ) {
printf("%lld %lld\n",k,k * ( k + 1 ) / 2);
return;
}
ll sum = 0;
for( int x : res ) sum += x;
printf("%lld %lld\n",res.size(),sum);
}
signed main() {
// cin.tie(nullptr),cout.tie(nullptr);
// ios::sync_with_stdio( 0 );
int T; cin >> T;while( T-- )solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
3 8 0 0 100 5050
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3848kb
input:
4 201 1000000000 1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...
output:
0 0 2 4 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0 0', found: '2 4'