QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#38989#1265. Total EclipseclaesWA 199ms8772kbC++2.0kb2022-07-08 11:13:232022-07-08 11:13:23

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 11:13:23]
  • Judged
  • Verdict: WA
  • Time: 199ms
  • Memory: 8772kb
  • [2022-07-08 11:13:23]
  • 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[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 ++ )
		{
		if(t == 5)
		{
			if( n > 30000) return 0 ;
		}
			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 ;
			}
		}
		printf( "%lld\n" , ans ) ;
	}
	return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 199ms
memory: 8772kb

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

result:

wrong answer 5th lines differ - expected: '5601933778666', found: '1'