Submission #409443

#TimeUsernameProblemLanguageResultExecution timeMemory
409443dualityLong Mansion (JOI17_long_mansion)C++11
100 / 100
1240 ms85700 KiB
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- int C[500000]; vi A[500000]; int pos[500000]; vi pos2[500000]; set<int> S; int l[1 << 20],r[1 << 20]; int build(int s,int e,int i) { if (s == e) { l[i] = 0,r[i] = 1e9; return 0; } int mid = (s+e) / 2; build(s,mid,2*i+1),build(mid+1,e,2*i+2); l[i] = 0,r[i] = 1e9; return 0; } int update(int s,int e,int as,int ae,int i,int ll,int rr) { if ((s > ae) || (e < as)) return 0; else if ((s >= as) && (e <= ae)) { l[i] = max(l[i],ll),r[i] = min(r[i],rr); return 0; } int mid = (s+e) / 2; update(s,mid,as,ae,2*i+1,ll,rr),update(mid+1,e,as,ae,2*i+2,ll,rr); return 0; } int L[500000],R[500000]; int queryAll(int s,int e,int i) { if (s == e) { L[s] = l[i],R[s] = r[i]; return 0; } int mid = (s+e) / 2; l[2*i+1] = max(l[2*i+1],l[i]); l[2*i+2] = max(l[2*i+2],l[i]); r[2*i+1] = min(r[2*i+1],r[i]); r[2*i+2] = min(r[2*i+2],r[i]); queryAll(s,mid,2*i+1),queryAll(mid+1,e,2*i+2); return 0; } int main() { int i,j; int N,Q,B; scanf("%d",&N); for (i = 0; i < N-1; i++) scanf("%d",&C[i]),C[i]--; for (i = 0; i < N; i++) { scanf("%d",&B); A[i].resize(B); for (j = 0; j < B; j++) scanf("%d",&A[i][j]),A[i][j]--; } build(0,N-1,0); for (i = 0; i < N; i++) pos[i] = N+1; for (i = N-1; i >= 0; i--) { S.insert(i); if (i < N-1) pos2[C[i]].pb(i); for (j = 0; j < A[i].size(); j++) { pos[A[i][j]] = i; while (!pos2[A[i][j]].empty()) { S.erase(pos2[A[i][j]].back()); pos2[A[i][j]].pop_back(); } } int b = (i == 0) ? N:pos[C[i-1]]-1; auto it = S.upper_bound(b); if (it != S.begin()) { it--; b = *it; if (i <= b) update(0,N-1,i,b,0,i,b); } } for (i = 0; i < N; i++) pos[i] = -1,pos2[i].clear(); S.clear(); for (i = 0; i < N; i++) { S.insert(i); if (i > 0) pos2[C[i-1]].pb(i); for (j = 0; j < A[i].size(); j++) { pos[A[i][j]] = i; while (!pos2[A[i][j]].empty()) { S.erase(pos2[A[i][j]].back()); pos2[A[i][j]].pop_back(); } } int b = (i == N-1) ? 0:pos[C[i]]+1; auto it = S.lower_bound(b); if (it != S.end()) { b = *it; if (b <= i) update(0,N-1,b,i,0,b,i); } } queryAll(0,N-1,0); int X,Y; scanf("%d",&Q); for (i = 0; i < Q; i++) { scanf("%d %d",&X,&Y); X--,Y--; if ((Y >= L[X]) && (Y <= R[X])) printf("YES\n"); else printf("NO\n"); } return 0; }

Compilation message (stderr)

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:117:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |         for (j = 0; j < A[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~
long_mansion.cpp:137:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |         for (j = 0; j < A[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~
long_mansion.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
long_mansion.cpp:105:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |     for (i = 0; i < N-1; i++) scanf("%d",&C[i]),C[i]--;
      |                               ~~~~~^~~~~~~~~~~~
long_mansion.cpp:107:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         scanf("%d",&B);
      |         ~~~~~^~~~~~~~~
long_mansion.cpp:109:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         for (j = 0; j < B; j++) scanf("%d",&A[i][j]),A[i][j]--;
      |                                 ~~~~~^~~~~~~~~~~~~~~
long_mansion.cpp:154:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  154 |     scanf("%d",&Q);
      |     ~~~~~^~~~~~~~~
long_mansion.cpp:156:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  156 |         scanf("%d %d",&X,&Y);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...