Submission #127104

#TimeUsernameProblemLanguageResultExecution timeMemory
127104eriksuenderhaufMatching (CEOI11_mat)C++11
100 / 100
510 ms48848 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define enl printf("\n") #define case(t) printf("Case #%d: ", (t)) #define ni(n) scanf("%d", &(n)) #define nl(n) scanf("%I64d", &(n)) #define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i]) #define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i]) #define pri(n) printf("%d\n", (n)) #define prl(n) printf("%I64d\n", (n)) #define pii pair<int, int> #define pll pair<long long, long long> #define vii vector<pii> #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef cc_hash_table<int,int,hash<int>> ht; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset; const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 1e6 + 5; const double eps = 1e-9; int nxl[MAXN], nxr[MAXN], b[MAXN]; int lp[MAXN], rp[MAXN], f[MAXN]; int s[MAXN], h[MAXN], a[MAXN]; int n, m; vi ans; int f1(int x) { if (x < 0) return x; if (nxl[x] == x) return x; return nxl[x] = f1(nxl[x]); } int f2(int x) { if (x >= n) return x; if (nxr[x] == x) return x; return nxr[x] = f2(nxr[x]); } bool g1(int x, int p) { return a[x - lp[p]] <= a[x] && a[x] <= a[x - rp[p]]; } bool g2(int x, int p) { return h[x - lp[p]] <= h[x] && h[x] <= h[x - rp[p]]; } int main() { ni(n), ni(m); for (int i = 0; i < n; i++) { ni(s[i]); s[i]--; a[s[i]] = i; nxl[i] = nxr[i] = i; } for (int i = n - 1; i >= 0; i--) { nxl[a[i]] = f1(a[i] - 1); nxr[a[i]] = f2(a[i] + 1); if (nxr[a[i]] < n) rp[i] = i - s[nxr[a[i]]]; if (nxl[a[i]] >= 0) lp[i] = i - s[nxl[a[i]]]; } int p = 0; for (int i = 1; i < n; i++) { while (p > 0 && !g1(i, p)) p = f[p]; if (g1(i, p)) p++; f[i + 1] = p; } p = 0; for (int i = 0; i < m; i++) { ni(h[i]); while (p > 0 && !g2(i, p)) p = f[p]; if (g2(i, p)) p++; if (p == n) ans.pb(i - n + 2), p = f[p]; } pri(ans.size()); for (int i: ans) printf("%d ", i); enl; return 0; }

Compilation message (stderr)

mat.cpp: In function 'int main()':
mat.cpp:11:34: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
 #define pri(n) printf("%d\n", (n))
                               ~~~^
mat.cpp:102:5: note: in expansion of macro 'pri'
     pri(ans.size());
     ^~~
mat.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     ni(n), ni(m);
          ^
mat.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
mat.cpp:7:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
mat.cpp:68:9: note: in expansion of macro 'ni'
         ni(s[i]);
         ^~
mat.cpp:7:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
mat.cpp:94:9: note: in expansion of macro 'ni'
         ni(h[i]);
         ^~
#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...