Submission #1166756

#TimeUsernameProblemLanguageResultExecution timeMemory
1166756TgX_2Matching (CEOI11_mat)C++20
100 / 100
905 ms64660 KiB
/*----------------------------- Author : TgX.2 11Ti - K28 - CHV -----------------------------*/ #include <bits/stdc++.h> using namespace std; #ifdef TGX #include "debug.h" #else #define debug(...) #endif #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i += 1) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i -= 1) #define fi first #define se second #define pb push_back #define len(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() #define _ << " " << #define __ << "\n" #define ___ << " " #define ______________TgX______________ main() #define int long long #define intmax 1e9 #define intmin -1e9 #define llongmax 1e18 #define llongmin -1e18 #define memo(a, val) memset((a), (val), sizeof((a))) struct custom { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template<class T1, class T2> using cmap = unordered_map<T1, T2, custom>; template<typename T1, typename T2> bool mini(T1 &a, T2 b) {if (a > b) a = b; else return 0; return 1;} template<typename T1, typename T2> bool maxi(T1 &a, T2 b) {if (a < b) a = b; else return 0; return 1;} /*-----------------------------*/ const int maxn = 1e6 + 7; int n, m, a[maxn], b[maxn]; namespace sub1 { bool check(int st) { vector<pair<int, int>> val; FOR(i, st, st + n - 1) val.pb({b[i], i - st + 1}); sort(all(val)); FOR(i, 0, n - 1) if (val[i].se != a[i + 1]) return 0; return 1; } void sol() { FOR(i, 1, n) cin >> a[i]; vector<int> val; FOR(i, 1, m) { cin >> b[i]; val.pb(b[i]); } sort(all(val)); val.erase(unique(all(val)), val.end()); FOR(i, 1, m) b[i] = lower_bound(all(val), b[i]) - val.begin() + 1; vector<int> ans; FOR(i, 1, m - n + 1) if (check(i)) ans.pb(i); cout << len(ans) __ ; for(const int &val : ans) cout << val ___ ; } }; const int mod = 2e9 + 11; pair<int, int> seg[maxn << 2]; int poww[maxn]; namespace sub2 { pair<int, int> merge(const pair<int, int> &a, const pair<int, int> &b) { int aa = a.fi + b.fi; int bb = (a.se * poww[b.fi] + b.se) % mod; return {aa, bb}; } void update(int id, int l, int r, int pos, int val) { if (pos < l or r < pos) return; if (l == r) { seg[id].fi = val > 0; seg[id].se = val; return; } int mid = (l + r) >> 1; update(id << 1, l, mid, pos, val); update(id << 1 | 1, mid + 1, r, pos, val); seg[id] = merge(seg[id << 1], seg[id << 1 | 1]); } void sol() { poww[0] = 1; int target = 0, tmp = 0; FOR(i, 1, n) { cin >> a[i]; a[i]--; poww[i] = (poww[i - 1] * n) % mod; target = (target * n + a[i]) % mod; tmp = (tmp * n + 1) % mod; } // FOR(i, 0, n) cout << poww[i] __ ; // debug(target, tmp); vector<int> val; FOR(i, 1, m) { cin >> b[i]; val.pb(b[i]); } sort(all(val)); FOR(i, 1, m) b[i] = lower_bound(all(val), b[i]) - val.begin() + 1; vector<int> ans; FOR(i, 1, n) update(1, 1, m, b[i], i); if ((seg[1].se - tmp + mod) % mod == target) ans.pb(1); // cout << (seg[1].se - tmp + mod) % mod __ ; FOR(i, 2, m - n + 1) { update(1, 1, m, b[i - 1], 0); update(1, 1, m, b[i + n - 1], i + n - 1); // cout << seg[1] __ ; if (((seg[1].se - i * tmp) % mod + mod) % mod == target) ans.pb(i); } cout << len(ans) __ ; for(const int &val : ans) cout << val ___ ; } }; void process() { cin >> n >> m; if (n <= 100 and m <= 100) sub1::sol(); else sub2::sol(); } /*-----------------------------*/ ______________TgX______________ { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("temp.inp", "r")) { freopen("temp.inp", "r", stdin); freopen("temp.out", "w", stdout); } process(); cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." __ ; } /*==============================+ |INPUT | --------------------------------| ================================+ |OUTPUT | --------------------------------| ===============================*/

Compilation message (stderr)

mat.cpp:28:41: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | #define ______________TgX______________ main()
      |                                         ^~~~
mat.cpp:178:1: note: in expansion of macro '______________TgX______________'
  178 | ______________TgX______________ {
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mat.cpp: In function 'int main()':
mat.cpp:182:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  182 |         freopen("temp.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mat.cpp:183:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  183 |         freopen("temp.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...