voidsolve(){ int n, m; cin >> n >> m; string s[n + 1]; for (int i = 1; i <= n; ++i)cin >> s[i], s[i] = "0" + s[i]; int dot = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (s[i][j] == '.')dot++; if (dot == 1and s[1][m] == '.') { bool a[n + 1][m + 1]; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) a[i][j] = false;
for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (s[i][j] == 'C') { a[i][j] = true; int num = 0; if (i - 1 >= 1and s[i - 1][j] == 'D') a[i - 1][j] = true, num++; if (j - 1 >= 1and s[i][j - 1] == 'R') a[i][j - 1] = true, num++;
if (j + 1 <= m and s[i][j + 1] == 'L') a[i][j + 1] = true, num++;
if (i + 1 <= n and s[i + 1][j] == 'U') a[i + 1][j] = true, num++; if (num != 2) return cout << "No" << endl, void(); } for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (s[i][j] != '.') if (a[i][j] == false) return cout << "No" << endl, void(); cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include<bits/stdc++.h> //#define endl '\n' #define int long long //#define N 103 #define fi first #define se second #define si(x) (int)(x.size()) #define all(x) x.begin(),x.end() #define debug cout<<"*******\n"; usingnamespace std;
typedef pair<int, int> PII;
template<classInfo> structSegmentTree { int n; std::vector<Info> info; SegmentTree() : n(0) {} SegmentTree(int n_, Info v_ = Info()) { init(n_, v_); } template<class T> SegmentTree(std::vector<T> init_){ init(init_); } voidinit(int n_, Info v_ = Info()){ init(std::vector(n_, v_)); } template<class T> voidinit(std::vector<T> init_){ n = init_.size(); info.assign(4 << std::__lg(n), Info()); std::function<void(int, int, int)> build = [&](int p, int l, int r) { if (r - l == 1) { info[p] = init_[l]; return; } int m = (l + r) / 2; build(2 * p, l, m); build(2 * p + 1, m, r); pull(p); }; build(1, 0, n); } voidpull(int p){ info[p] = info[2 * p] + info[2 * p + 1]; } voidmodify(int p, int l, int r, int x, const Info &v){ if (r - l == 1) { info[p] = v; return; } int m = (l + r) / 2; if (x < m) { modify(2 * p, l, m, x, v); } else { modify(2 * p + 1, m, r, x, v); } pull(p); } voidmodify(int p, const Info &v){ modify(1, 0, n, p, v); } Info rangeQuery(int p, int l, int r, int x, int y){ if (l >= y || r <= x) { returnInfo(); } if (l >= x && r <= y) { return info[p]; } int m = (l + r) / 2; returnrangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m, r, x, y); } Info rangeQuery(int l, int r){ returnrangeQuery(1, 0, n, l, r); } };
structInfo { int l = 1; int r = 1; int cnt = 0; };
Info operator+(Info a, Info b) { if (a.r == 0 && b.l == 0) { a.cnt += b.cnt - 1; a.r = b.r; } else { a.cnt += b.cnt; a.r = b.r; } return a; }
voidsolve(){ int n; cin >> n; vector<Info> init(n); vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; init[i].l = 0, init[i].r = 0, init[i].cnt = 1; } SegmentTree<Info> seg(init); int cnt = 0,pre = 0; int ans = 0; for (int i = 0; i < n; ++i) { int p = a[i]; p--; seg.modify(p, {1, 1, 0}); Info info = seg.rangeQuery(0, p); cnt = info.cnt; ans += max(cnt - pre,0ll); pre = cnt; } if (cnt) ans += cnt; cout << ans << endl; }
signedmain(){ // freopen("in.txt", "r", stdin); cin.tie(nullptr), cout.tie(nullptr); ios::sync_with_stdio(false); cout.precision(10); cout << fixed; int T = 1; // cin >> T; while (T--) solve(); return0; }