QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#38934#1265. Total EclipseJamiiiiiiWA 44ms7060kbC++1.9kb2022-07-08 10:28:302022-07-08 10:28:32

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-08 10:28:32]
  • Judged
  • Verdict: WA
  • Time: 44ms
  • Memory: 7060kb
  • [2022-07-08 10:28:30]
  • Submitted

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[200010] , zx[200010] , 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;
		}
		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 ;
					if( cx( a[i].bh ) != cx( zx[j] ) )
					{
						hb( a[i].bh , zx[j] ) ;
						lt -- ;
					}
				}
			}
			if( i != n - 1 )
			{
				ans += (long long)lt * ( a[i].br - a[i + 1].br ) ;
			}
			else
			{
				ans += (long long)lt * a[i].br ;
			}
		}
		printf( "%lld\n" , ans ) ;
		return 0;
	}
	return 0 ;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 5884kb

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: 44ms
memory: 7060kb

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

result:

wrong answer 2nd lines differ - expected: '16659615874110', found: ''