Submission #643447

#TimeUsernameProblemLanguageResultExecution timeMemory
643447uyluluMatching (CEOI11_mat)C++14
28 / 100
495 ms44756 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define endl "\n" const int N = 1e6 + 5; int pos[N],pi[N*2]; int a[N],b[N],le[N],ri[N],ra[N],n,m; vector<int> nw; bool check(int idx,int mid) { if(mid > n) return false; return nw[idx] >= nw[idx - le[mid]] && nw[idx] <= nw[idx - ri[mid]]; } struct BIT{ vector<int> bit; int n; void init(int len) { n = len; bit.resize(n + 1,0); } void addUP(int pos,int x) { for(int i = pos;i <= n;i += i&(-i)) { bit[i] = max(bit[i],x); } } void addDown(int pos,int x) { while(pos > 0) { bit[pos] = max(bit[pos],x); pos -= pos&(-pos); } } int queryUP(int pos) { int res = 0; for(int i = pos;i <= n;i += i&(-i)) { res = max(res,bit[i]); } return res; } int queryDown(int pos) { int res = 0; while(pos > 0) { res = max(res,bit[pos]); pos -= pos&(-pos); } return res; } }; BIT front,back; signed main() { // freopen("mat10a.in","r",stdin); // freopen("some.txt","w",stdout); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>m; for(int i = 1;i <= n;i++) { cin>>ra[i]; a[ra[i]] = i; } for(int i = 1;i <= m;i++) { cin>>b[i]; } set<int> st; front.init(n); back.init(n); for(int i = 1;i <= n;i++) { int l = front.queryDown(a[i]); if(l == 0) { le[i] = 0; } else le[i] = i - ra[l]; int r = back.queryUP(a[i]); if(r == 0) { ri[i] = 0; } else { ri[i] = i - ra[r]; } front.addUP(a[i],a[i]); back.addDown(a[i],a[i]); } for(int i= 1;i <= n;i++) { nw.push_back(a[i]); } nw.push_back(-1); for(int i = 1;i <= m;i++) { nw.push_back(b[i]); } pi[0] = 0; for(int i = 1;i < nw.size();i++) { if(i == n) { pi[i] = 0; continue; } int j = pi[i - 1]; while(j > 0 && !check(i,j + 1)) { j = pi[j - 1]; } if(check(i,j + 1)) { j++; } pi[i] = j; } vector<int> pos; for(int i = n + 1;i < nw.size();i++) { if(pi[i] == n) { pos.push_back(i - n*2 + 1); } } cout<<pos.size()<<endl; for(auto u : pos) cout<<u<<" "; }

Compilation message (stderr)

mat.cpp: In function 'int main()':
mat.cpp:98:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |  for(int i = 1;i < nw.size();i++) {
      |                ~~^~~~~~~~~~~
mat.cpp:113:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |  for(int i = n + 1;i < nw.size();i++) {
      |                    ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...