QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#864763#5650. Beppa and SwerChatmajonator#WA 5ms3712kbC++202.6kb2025-01-21 00:35:052025-01-21 00:35:06

Judging History

你现在查看的是最新测评结果

  • [2025-01-21 00:35:06]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3712kb
  • [2025-01-21 00:35:05]
  • 提交

answer

#include <bits/stdc++.h>

#define el '\n'
#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define rforn(i,n) for(int i =(int)(n) - 1; i>= 0; --i)
#define fora(i,x,n) for(int i=(int)x; i< (int)n; ++i)
#define rfora(i,x,n) for(int i=(int)x; i>= (int)n; --i)
#define pb push_back
#define pob pop_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) ((int)v.size())
#define CYN(x) cout << (x ? "YES" : "NO" ) <<endl; 
#define cases(t) while(t--)
#define mem(v, val) memset(v, (val), sizeof(v))
#define D(x) cout << #x << ": " << x << endl;
#define precision(x) cout<<setprecision(x)<<fixed;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<char,int> pci;
// typedef tuple<int, int, int> tiii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef map<int,int> mpii;
// typedef unordered_map<int,int> umpii;
typedef set<int> seti;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;

const int inf = 1e9;
const int nax = 1e5+5;
const ld pi = acos(-1);
const ld eps = 1e-9;

int dr[] = {1,-1,0,0,1,-1,-1,1};
int dc[] = {0,0,1,-1,1,1,-1,-1};

ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll mod(ll a, ll b) { return (((a % b) + b) % b); }
  
void solve(){
    int n; cin>>n;
    vi a(n), b(n), posa(n), posb(n);
    forn(i,n){
        cin>>a[i];
        a[i]--;
        posa[a[i]] = i;
    }
    forn(i,n) cin>>b[i], b[i]--;

    int ans = 0, lst = n;
    vi vis(n);
    rforn(i,n){
        int pos = posa[b[i]];
        if(pos <= lst){
            vis[pos] = 1;
            fora(j,pos+1,lst){
                vis[j] = 1;
                ans++;
            }
            lst = pos;
        }else{
            if(!vis[b[i]]) ans++;
        }
        // D(i); D(ans);
    }

    cout<<ans<<el;
}

int main(){
    ios_base::sync_with_stdio(false),
    cin.tie(NULL);
    precision(20);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int t = 1; 
    cin>>t;
    cases(t) solve();
    return 0;
}

//Compile: 
//g++ --std=c++17 B.cpp -o a
//How to run the file in any terminal
//./D
//How pass the input in the file
// Input data
//./D < input.txt 
// Input data and generate output file
//./D < input.txt > output.txt

// g++ -o a -std=c++20 D.cpp

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

4
5
1 4 2 5 3
4 5 1 2 3
6
1 2 3 4 5 6
1 2 3 4 5 6
8
8 2 4 7 1 6 5 3
5 6 1 4 8 2 7 3
1
1
1

output:

2
0
4
0

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 5ms
memory: 3712kb

input:

10000
2
2 1
2 1
2
2 1
1 2
3
3 1 2
3 1 2
3
2 3 1
2 1 3
3
1 3 2
3 1 2
3
1 2 3
3 1 2
3
2 3 1
3 1 2
3
3 2 1
1 2 3
4
3 2 4 1
3 2 4 1
4
1 4 2 3
1 4 3 2
4
4 2 3 1
4 3 2 1
4
4 1 2 3
4 3 1 2
4
2 1 3 4
2 3 4 1
4
3 1 2 4
3 4 2 1
4
3 4 2 1
4 3 2 1
4
3 1 4 2
1 3 2 4
4
2 4 1 3
1 2 4 3
4
4 1 3 2
2 4 1 3
4
3 1 4 2
...

output:

0
1
0
2
1
1
2
2
0
1
1
1
2
2
1
3
1
1
2
2
2
2
2
2
2
2
3
3
3
3
3
3
0
2
1
1
3
3
1
3
1
1
2
3
2
3
2
2
2
2
3
3
3
3
4
3
1
3
2
2
4
3
1
2
1
1
2
2
2
2
2
2
2
2
3
4
3
3
3
3
2
3
2
2
3
3
2
3
2
2
3
4
2
2
2
2
2
2
3
4
4
3
4
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
...

result:

wrong answer 10th lines differ - expected: '3', found: '1'