QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#729653#4937. Permutation Transformationpnlong2706RE 0ms0kbC++173.5kb2024-11-09 17:33:512024-11-09 17:33:52

Judging History

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

  • [2024-11-09 17:33:52]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-09 17:33:51]
  • 提交

answer

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll          long long
#define ull         unsigned long long
#define ld          long double
#define for_(n)     for(ll i=0; i<n; i++)
#define for__(a,b)  for(ll i=a; i<b; i++)
#define _for(i,a,b) for(ll i=a; i<b; i++)
#define mp          make_pair
#define fi          first
#define se          second
#define pb          push_back
#define pii         pair<int, int>
#define pll         pair<long long, long long>
#define el          "\n"
#define debug(x)    if(enable_debug) cerr << "[debug] " << #x << " : " << x << endl;
#define M_PI        3.14159265358979323846

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

typedef tree<ll,null_type, less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const long long MOD=(ll)1e9+7;
const bool enable_debug = true;

template<class T, class P>
ostream& operator<<(ostream& os, const pair<T,P> &a) { os << "{" << a.first << ";" << a.second << "}"; return os; }
template<class T>
ostream& operator<<(ostream& os, const vector<T> &a) { ; for(auto it: a) os << it << " "; ; return os; }
template<class T>
ostream& operator<<(ostream& os, const deque<T> &a) { ; for(auto it: a) os << it << " "; ; return os; }
template<class T>
ostream& operator<<(ostream& os, const set<T> &a) { ; for(auto it: a) os << it << " "; ; return os; }
template<class T>
ostream& operator<<(ostream& os, const multiset<T> &a) { ; for(auto it: a) os << it << " "; ; return os; }

ll gcd(ll a, ll b) { return b==0? a : gcd(b,a%b); }
ll lcm(ll a, ll b) { return a/(gcd(a,b))*b; }

ll pow_mod(ll x, ll y, ll mod) { //mod<3.10^9
    ll ans=1;
    while(y>0) {
        if(y%2==1) ans=ans*x%mod;
        y=y>>1;
        x=x*x%mod;
    }
    return ans%mod;
}

void solve(int ith) {
    int n, m;
    cin >> n >> m;
    vector<int> a(2*n+1, -1), b(2*n+1, -1);

    for_(n) cin >> a[i] >> b[i];
    for__(n, 2*n) {
        a[i] = a[i-n];
        b[i] = b[i-n];
    }

    vector<bool> vis(m+1, false);
    int fid = 2*n;

    for_(2*n) {
        if(vis[a[i]] && vis[b[i]]) {
            a[i] = -1;
            b[i] = -1;
            fid = min(fid, (int)i);
        }
        else if(vis[a[i]]) {
            a[i] = b[i];
            b[i] = -1;
        }
        else if(vis[b[i]]) b[i] = -1;
        if(a[i]!=-1) vis[a[i]] = true;
    }

    // debug(b);
    // debug(a);

    vector<int> ls(m+1, fid);
    vector<int> mnid(m+1, fid);
    for(int i=fid-1; i>=0; i--) {
        // discard a[i]
        if(b[i]==-1) {
            mnid[a[i]] = i;
        }
        else {
            mnid[a[i]] = mnid[b[i]];
        }
    }

    vector<int> ans(n);

    for(int i=1; i<=m; i++) {
        ans[mnid[i]%n]++;
    }

    for(auto v: ans) cout << v << el;
}

// PLEASE DO CHECK THE CASE THAT YOU CHANGE THE ORIGINAL VALUE OF SOME VAR AND THEN TRY TO USE THE OLD VALUE OF THAT VAR FOR
// ANOTHER EVALUATION IN THE SAME SCOPE

int main() {
    clock_t begin=clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    #ifndef ONLINE_JUDGE
    freopen("INP.inp","r",stdin);
    freopen("OUT.out", "w", stdout);
    #endif

    int t = 1;
    //cin >> t;
    for_(t)
        solve(i+1);
    cerr << "TIME : " << (double)(clock()-begin)/CLOCKS_PER_SEC << "s.";
    return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

5
3 5 1 2 4

output:


result: