Submission #132086

# Submission time Handle Problem Language Result Execution time Memory
132086 2019-07-18T09:45:44 Z MvC Bridges (APIO19_bridges) C++11
29 / 100
828 ms 8900 KB
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
//#include "job.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mmax=1e3+50;
const int mod=1e9+7;
using namespace std;
int x,y,z,nr,vz[mmax],q,i,t,n,m,vl[nmax],st[4*nmax],l,r,mid,lb,rb;
vector<pair<pair<int,int>,int> >e;
vector<int>a[nmax];
void dfs(int x,int z)
{
	vz[x]=1;
	nr++;
	for(int i=0;i<a[x].size();i++)
	{
		int y=a[x][i],u=x^e[y].fr.fr^e[y].fr.sc;
		if(vz[u] || e[y].sc<z)continue;
		dfs(u,z);
	}
}
void upd(int nod,int l,int r,int p)
{
	if(l==r)
	{
		st[nod]=vl[l];
		return;
	}
	int mid=(l+r)/2;
	if(p<=mid)upd(2*nod,l,mid,p);
	else upd(2*nod+1,mid+1,r,p);
	st[nod]=min(st[2*nod],st[2*nod+1]);
}
int qry(int nod,int l,int r,int tl,int tr)
{
	if(tr<l || tl>r)return inf;
	if(tl<=l && r<=tr)return st[nod];
	int mid=(l+r)/2;
	return min(qry(2*nod,l,mid,tl,tr),qry(2*nod+1,mid+1,r,tl,tr));
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>m;
	for(i=1;i<=4*n;i++)st[i]=inf;
	for(i=1;i<=m;i++)
	{
		cin>>x>>y>>z;
		a[x].pb(i-1);
		a[y].pb(i-1);
		e.pb(mkp(mkp(x,y),z));
		vl[x]=z;
		upd(1,1,n,x);
	}
	cin>>q;
	if(n<=1000 && m<=1000 && q<=10000)
	{
		while(q--)
		{
			cin>>t>>x>>z;
			if(t==1)
			{
				x--;
				e[x].sc=z;
			}
			else
			{
				memset(vz,0,sizeof(vz));
				nr=0;
				dfs(x,z);
				cout<<nr<<'\n';
			}
		}
		return 0;
	}
	else if(m==n-1)
	{
		while(q--)
		{
			cin>>t>>x>>z;
			if(t==1)
			{
				x--;
				e[x].sc=z;
				vl[e[x].fr.fr]=z;
				upd(1,1,n,e[x].fr.fr);
			}
			else
			{
				l=1,r=x-1,lb=-1;
				while(l<=r)
				{
					mid=(l+r)/2;
					if(qry(1,1,n,mid,x-1)>=z)lb=mid,r=mid-1;
					else l=mid+1;
				}
				l=x,r=n-1,rb=-1;
				while(l<=r)
				{
					mid=(l+r)/2;
					if(qry(1,1,n,x,mid)>=z)rb=mid,l=mid+1;
					else r=mid-1;
				}
				if(lb==-1 && rb==-1)cout<<1<<'\n';
				else if(lb==-1)cout<<rb+1-x+1<<'\n';
				else if(rb==-1)cout<<x-lb+1<<'\n';
				else cout<<rb+1-lb+1<<'\n';
			}
		}
	}
    return 0;
}

Compilation message

bridges.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("O3")
 
bridges.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("unroll-loops")
 
bridges.cpp: In function 'void dfs(int, int)':
bridges.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a[x].size();i++)
              ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 57 ms 2936 KB Output is correct
4 Correct 10 ms 2936 KB Output is correct
5 Correct 13 ms 2936 KB Output is correct
6 Correct 11 ms 2936 KB Output is correct
7 Correct 11 ms 2808 KB Output is correct
8 Correct 11 ms 2936 KB Output is correct
9 Correct 13 ms 2808 KB Output is correct
10 Correct 9 ms 2936 KB Output is correct
11 Correct 9 ms 2808 KB Output is correct
12 Correct 9 ms 2812 KB Output is correct
13 Correct 13 ms 2808 KB Output is correct
14 Correct 11 ms 2808 KB Output is correct
15 Correct 14 ms 2808 KB Output is correct
16 Correct 12 ms 2808 KB Output is correct
17 Correct 12 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 472 ms 8496 KB Output is correct
2 Correct 468 ms 8720 KB Output is correct
3 Correct 469 ms 8772 KB Output is correct
4 Correct 469 ms 8780 KB Output is correct
5 Correct 461 ms 8752 KB Output is correct
6 Correct 514 ms 8884 KB Output is correct
7 Correct 507 ms 8752 KB Output is correct
8 Correct 511 ms 8752 KB Output is correct
9 Correct 39 ms 4344 KB Output is correct
10 Correct 471 ms 7648 KB Output is correct
11 Correct 475 ms 7600 KB Output is correct
12 Correct 828 ms 8900 KB Output is correct
13 Correct 176 ms 8624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 432 ms 7312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 92 ms 7808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 472 ms 8496 KB Output is correct
2 Correct 468 ms 8720 KB Output is correct
3 Correct 469 ms 8772 KB Output is correct
4 Correct 469 ms 8780 KB Output is correct
5 Correct 461 ms 8752 KB Output is correct
6 Correct 514 ms 8884 KB Output is correct
7 Correct 507 ms 8752 KB Output is correct
8 Correct 511 ms 8752 KB Output is correct
9 Correct 39 ms 4344 KB Output is correct
10 Correct 471 ms 7648 KB Output is correct
11 Correct 475 ms 7600 KB Output is correct
12 Correct 828 ms 8900 KB Output is correct
13 Correct 176 ms 8624 KB Output is correct
14 Incorrect 432 ms 7312 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 57 ms 2936 KB Output is correct
4 Correct 10 ms 2936 KB Output is correct
5 Correct 13 ms 2936 KB Output is correct
6 Correct 11 ms 2936 KB Output is correct
7 Correct 11 ms 2808 KB Output is correct
8 Correct 11 ms 2936 KB Output is correct
9 Correct 13 ms 2808 KB Output is correct
10 Correct 9 ms 2936 KB Output is correct
11 Correct 9 ms 2808 KB Output is correct
12 Correct 9 ms 2812 KB Output is correct
13 Correct 13 ms 2808 KB Output is correct
14 Correct 11 ms 2808 KB Output is correct
15 Correct 14 ms 2808 KB Output is correct
16 Correct 12 ms 2808 KB Output is correct
17 Correct 12 ms 2808 KB Output is correct
18 Correct 472 ms 8496 KB Output is correct
19 Correct 468 ms 8720 KB Output is correct
20 Correct 469 ms 8772 KB Output is correct
21 Correct 469 ms 8780 KB Output is correct
22 Correct 461 ms 8752 KB Output is correct
23 Correct 514 ms 8884 KB Output is correct
24 Correct 507 ms 8752 KB Output is correct
25 Correct 511 ms 8752 KB Output is correct
26 Correct 39 ms 4344 KB Output is correct
27 Correct 471 ms 7648 KB Output is correct
28 Correct 475 ms 7600 KB Output is correct
29 Correct 828 ms 8900 KB Output is correct
30 Correct 176 ms 8624 KB Output is correct
31 Incorrect 432 ms 7312 KB Output isn't correct
32 Halted 0 ms 0 KB -