제출 #643444

#제출 시각아이디문제언어결과실행 시간메모리
643444uyluluMatching (CEOI11_mat)C++14
36 / 100
2090 ms7144 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]]; } signed main() { // freopen("in.txt","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; for(int i = 1;i <= n;i++) { int x = a[i]; auto it = lower_bound(st.begin(),st.end(),x); if(it == st.begin()) { le[i] = 0; } else { it--; le[i] = i - ra[*it]; } it = lower_bound(st.begin(),st.end(),x); if(it == st.end()) { ri[i] = 0; } else { ri[i] = i - ra[*it]; } st.insert(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<<" "; }

컴파일 시 표준 에러 (stderr) 메시지

mat.cpp: In function 'int main()':
mat.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i = 1;i < nw.size();i++) {
      |                ~~^~~~~~~~~~~
mat.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |  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...