QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#729653 | #4937. Permutation Transformation | pnlong2706 | RE | 0ms | 0kb | C++17 | 3.5kb | 2024-11-09 17:33:51 | 2024-11-09 17:33:52 |
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