是数据水了吗
查看原帖
是数据水了吗
819273
LIUYC_C楼主2023/8/19 20:24

场上没想二分,想打暴力,但过了,应该可以hack吧

#include <bits/stdc++.h>
using namespace std;
const int N=1010100;

unordered_map<int,int> cnt;
unordered_map<int,vector<int>> start;
int s[N];
int q[N];
unordered_map<int,int> hashs;

int main(){
  int n,m,opt1,opt2;
  ios::sync_with_stdio(false);
  cin>>n>>m>>opt1>>opt2;
  for(int i=1;i<=n;i++){
    cin>>s[i];
    start[s[i]].push_back(i);
    cnt[s[i]]++;
  }

  int k=0;
  int ans=0;

  int last=0;
  int now;
  for(int i=1;i<=m;i++){
     
    int x;
    cin>>x;
    if(cnt[x]){
      ans++;
    }
    else if(!cnt[x]){
      continue;
    }
    
    int len=start[x].size();
    if(start[x][len-1]<=last){
        k++;
        now=start[x][0];
        last=now;
        continue;
    }
    
    for(auto t:start[x]){
        if(t>last){
            now=t;
            break;
        }
    }
    
    last=now;
  }
  cout<<ans*opt1<<" "<<(k+1)*opt2<<endl;

}   
2023/8/19 20:24
加载中...