Submission #1097378

# Submission time Handle Problem Language Result Execution time Memory
1097378 2024-10-07T05:10:38 Z 8pete8 Long Mansion (JOI17_long_mansion) C++17
0 / 100
95 ms 20220 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
#define double long double
using namespace std;
const int mod=998244353,mxn=2e5+5,inf=1e18,minf=-1e18,lg=62;
//#undef int
int n,k,m,q;
void setIO(string name){		
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);		
	freopen((name+".out").c_str(),"w",stdout);	
}
int door[mxn+10],where[mxn+10],wheredoor[mxn+10],id=0,del[mxn+10],have[mxn+10];
vector<pii>add1[mxn+10],add2[mxn+10];
vector<int>rem[mxn+10];
pii ans[mxn+10];
int32_t main(){
    fastio
	int n;cin>>n;
	for(int i=1;i<=n-1;i++)cin>>door[i],have[door[i]]=1;
	for(int i=1;i<=n;i++){
		int a;cin>>a;
		for(int j=0;j<a;j++){
			int x;cin>>x;
			where[x]=i;
		}
		if(i<n&&where[door[i]]<=wheredoor[door[i]]){
			++id;
			add1[wheredoor[door[i]]+1].pb({wheredoor[door[i]]+1,id});
			add2[wheredoor[door[i]]+1].pb({i,id});
			rem[i+1].pb(id);
		}
		wheredoor[door[i]]=i;
	}
    for(int i=1;i<=n;i++){
		if(where[i]<=wheredoor[i]&&have[i]){
			++id;
			add1[wheredoor[i]+1].pb({wheredoor[i]+1,id});
			add2[wheredoor[i]+1].pb({n,id});
		}
    }
	priority_queue<pii,vector<pii>,greater<pii>>r;
	priority_queue<pii>l;
	r.push({n+1,0});
	l.push({0,0});
	for(int i=1;i<=n;i++){
		for(auto j:add1[i])l.push(j);
        for(auto j:add2[i])r.push(j);
		for(auto j:rem[i])del[j]=1;
		while(!l.empty()&&del[l.top().s])l.pop();
		while(!r.empty()&&del[r.top().s])r.pop();
		ans[i]={l.top().f,r.top().f};
	}
	int q;cin>>q;
	while(q--){
		int a,b;cin>>a>>b;
		if(b>=ans[a].f&&b<=ans[a].s)cout<<"YES\n";
		else cout<<"NO\n";
	}
}
/*

lets say we are at point x
if there exist a "color" of key where
door i seperates room i,i+1
the last appearance of door before x and first after x (l,r)
l<x and x<=r
and the last appearance of room with that color of key before x and first after x (l2,r2)
if l2 <= l < r < r2
then no matter how we move we cant go outside the range (l+1,r)
*/

Compilation message

long_mansion.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   32 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
long_mansion.cpp:39:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   39 | void setIO(string name){
      |                       ^
long_mansion.cpp:48:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   48 | int32_t main(){
      |              ^
long_mansion.cpp: In function 'void setIO(std::string)':
long_mansion.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:42:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 20220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14684 KB Output isn't correct
2 Halted 0 ms 0 KB -