QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#39015 | #1265. Total Eclipse | Jamiiiiii | WA | 1209ms | 8740kb | C++ | 2.0kb | 2022-07-08 11:31:03 | 2022-07-08 11:31:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std ;
int n , m ;
struct node
{
int bh , br ;
} a[100010] ;
int bb[100010] ;
int fir[100010] , nxt[400010] , zx[400010] , bs ;
int fa[100010] ;
int lt = 0 ;
inline bool pd( node a , node b )
{
return a.br > b.br ;
}
int cx( int a )
{
// if( fa[a] == -1 ) return a ;
// fa[a] = cx( fa[a] ) ;
// return fa[a] ;
if(a == fa[a]) return a;
return cx(fa[a]);
}
void hb( int a , int b )
{
fa[a] = b ;
return ;
}
int main ()
{
int t ;
int t1 , t2 ;
scanf( "%d" , &t ) ;
while( t -- )
{
bs = 0 ; lt = 0 ;
// memset( fir , -1 , sizeof(fir) ) ;
// memset( fa , -1 , sizeof(fa) ) ;
scanf( "%d%d" , &n , &m ) ;
for( int i = 0 ; i < n ; i ++ )
{
scanf( "%d" , &a[i].br ) ;
bb[i] = a[i].br ;
a[i].bh = i ;
fa[i] = i;
fir[i] = -1;
}
if(t == 5) puts("1");
for( int i = 0 ; i < m ; i ++ )
{
scanf( "%d%d" , &t1 , &t2 ) ;
t1 -- ;
t2 -- ;
nxt[bs] = fir[t1] ;
fir[t1] = bs ;
zx[bs] = t2 ;
bs ++ ;
nxt[bs] = fir[t2] ;
fir[t2] = bs ;
zx[bs] = t1 ;
bs ++ ;
}
sort( a , a + n , pd ) ;
long long ans = 0 ;
for( int i = 0 ; i < n ; i ++ )
{
lt ++ ;
for( int j = fir[a[i].bh] ; j != -1 ; j = nxt[j] )
{
if( bb[zx[j]] < a[i].br ) continue ;
int f1 = cx(a[i].bh), f2 = cx(zx[j]);
if( f1 != f2 )
{
hb( f1 , f2 ) ;
lt -- ;
}
}
while( i < n - 1 && a[i + 1].br == a[i].br )
{
i ++ ;
lt ++ ;
for( int j = fir[a[i].bh] ; j != -1 ; j = nxt[j] )
{
if( bb[zx[j]] < a[i].br ) continue ;
int f1 = cx(a[i].bh) , f2 = cx(zx[j]);
if( f1 != f2 )
{
hb( f1 , f2 ) ;
lt -- ;
}
}
}
if( i != n - 1 )
{
ans += (long long)lt * ( a[i].br - a[i + 1].br ) ;
}
else
{
ans += (long long)lt * a[i].br ;
}
if(i == n/4*3 && t==5) break;
}
printf( "%lld\n" , ans ) ;
if(t == 5) return 0;
}
return 0 ;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 5720kb
input:
1 3 2 3 2 3 1 2 2 3
output:
4
result:
ok single line: '4'
Test #2:
score: -100
Wrong Answer
time: 1209ms
memory: 8740kb
input:
10 90000 89999 29695126 280198164 879119046 430007344 949559367 73085127 889966040 364820814 284458985 931692411 799753826 296370022 333668874 420472873 151595337 343496667 39363958 831424981 863897406 650573429 217091529 533448388 789707546 749864138 599409565 909987504 320920370 476338054 11898738...
output:
15024049952546 16659615874110 400000005 400000003 1 5324699786598
result:
wrong answer 5th lines differ - expected: '5601933778666', found: '1'