QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#628415#8046. Rock-Paper-Scissors Pyramidlonelywolf#WA 312ms158752kbC++205.1kb2024-10-10 20:06:102024-10-10 20:06:11

Judging History

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

  • [2024-10-10 20:06:11]
  • 评测
  • 测评结果:WA
  • 用时:312ms
  • 内存:158752kb
  • [2024-10-10 20:06:10]
  • 提交

answer

#include <bits/stdc++.h>  
using namespace std;  

#define int long long  

template<class Info, class Tag>
struct LazySegmentTree {
    int n;
    vector<Info> info;
    vector<Tag> tag;
    LazySegmentTree() : n(0) {}
    LazySegmentTree(int n_, Info v_ = Info()) {
        init(n_, v_);
    }
    template<class T>
    LazySegmentTree(vector<T> init_) {
        init(init_);
    }
    void init(int n_, Info v_ = Info()) {
        init(vector(n_ + 1, v_));
    }
    template<class T>
    void init(vector<T> init_) {
        n = init_.size() - 1;
        info.assign(4 << __lg(n) + 1, Info());
        tag.assign(4 << __lg(n) + 1, Tag());
        function<void(int, int, int)> build = [&](int p, int l, int r) {
            if (l == r) {
                info[p] = init_[l];
                return;
            }
            int m = (l + r) / 2;
            build(2 * p, l, m);
            build(2 * p + 1, m + 1, r);
            pull(p);
        };
        build(1, 1, n);
    }
    void pull(int p) {
        info[p] = info[2 * p] + info[2 * p + 1];
    }
    void apply(int p, const Tag &v) {
        info[p].apply(v);
        tag[p].apply(v);
    }
    void push(int p) {
        apply(2 * p, tag[p]);
        apply(2 * p + 1, tag[p]);
        tag[p] = Tag();
    }
    void modify(int p, int l, int r, int x, const Info &v) {
        if (l == r) {
            info[p] = v;
            return;
        }
        int m = (l + r) / 2;
        push(p);
        if (x <= m) {
            modify(2 * p, l, m, x, v);
        } else {
            modify(2 * p + 1, m + 1, r, x, v);
        }
        pull(p);
    }
    void modify(int p, const Info &v) {
        modify(1, 1, n, p, v);
    }
    Info rangeQuery(int p, int l, int r, int x, int y) {
        if (l > y || r < x) {
            return Info();
        }
        if (l >= x && r <= y) {
            return info[p];
        }
        int m = (l + r) / 2;
        push(p);
        return rangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m + 1, r, x, y);
    }
    Info rangeQuery(int l, int r) {
        return rangeQuery(1, 1, n, l, r);
    }
    void rangeApply(int p, int l, int r, int x, int y, const Tag &v) {
        if (l > y || r < x) {
            return;
        }
        if (l >= x && r <= y) {
            apply(p, v);
            return;
        }
        int m = (l + r) / 2;
        push(p);
        rangeApply(2 * p, l, m, x, y, v);
        rangeApply(2 * p + 1, m + 1, r, x, y, v);
        pull(p);
    }
    void rangeApply(int l, int r, const Tag &v) {
        return rangeApply(1, 1, n, l, r, v);
    }
	template<class F>
    int findFirst(int p, int l, int r, int x, int y, F pred) {
        if (l > y || r < x || !pred(info[p])) {
            return -1;
        }
        if (l == r) {
            return l;
        }
        int m = (l + r) / 2;
        push(p);
        int res = findFirst(2 * p, l, m, x, y, pred);
        if (res == -1) {
            res = findFirst(2 * p + 1, m + 1, r, x, y, pred);
        }
        return res;
    }
    template<class F>
    int findFirst(int l, int r, F pred) {
        return findFirst(1, 1, n, l, r, pred);
    }
    template<class F>
    int findLast(int p, int l, int r, int x, int y, F pred) {
        if (l > y || r < x || !pred(info[p])) {
            return 0;
        }
        if (l == r) {
            return l;
        }
        int m = (l + r) / 2;
        push(p);
        int res = findLast(2 * p + 1, m + 1, r, x, y, pred);
        if (res == -1) {
            res = findLast(2 * p, l, m, x, y, pred);
        }
        return res;
    }
    template<class F>
    int findLast(int l, int r, F pred) {
        return findLast(1, 1, n, l, r, pred);
    }
};
struct Tag {
	int val = -1;
    void apply(Tag t) {
    	val = t.val;
	}
};
struct Info {
	array<int, 3> cnt{};
    void apply(Tag t) {
    	int s = cnt[0] + cnt[1] + cnt[2];
    	cnt[0] = cnt[1] = cnt[2] = 0;
    	cnt[t.val] = s;
    }
};
Info operator+(Info a, Info b) {
	for (int i = 0; i < 3; i++) {
		a.cnt[i] += b.cnt[i];
	}
	return a;
}

void solve() {
	string s;
	cin >> s;

	int n = s.size();
	s = " " + s;

	LazySegmentTree<Info, Tag> tr(n);
	
	vector<int> lst(4);
	char ans = 0;
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'R') {
			int pos = lst[1];
			tr.rangeApply(pos + 1, i, {3});
			if (pos == 0) {
				ans = s[i];
			}
			lst[3] = i;
			lst[2] = tr.findLast(1, n, [&](Info x) {
				return x.cnt[2] > 0;
			});
		} else if (s[i] == 'S') {
			int pos = lst[3];
			tr.rangeApply(pos + 1, i, {2});
			if (pos == 0) {
				ans = s[i];
			}
			lst[2] = i;

			lst[1] = tr.findLast(1, n, [&](Info x) {
				return x.cnt[1] > 0;
			});
		} else {
			int pos = lst[2];
			tr.rangeApply(pos + 1, i, {1});
			if (pos == 0) {
				ans = s[i];
			}
			lst[1] = i;

			lst[3] = tr.findLast(1, n, [&](Info x) {
				return x.cnt[3] > 0;
			});
		}
	}

	cout << ans << "\n";
}

signed main() {  
    ios::sync_with_stdio(false);
    cin.tie(nullptr);  

    int t;
    cin >> t;
    while (t--) {
    	solve();
    }

    return 0;
}  
  

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3568kb

input:

2
SPR
SPSRRP

output:

S
P

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 312ms
memory: 158752kb

input:

1
RPPSRPPRSRSRRRPPSPRPRSRRSRRPPPRSPSSRRRSPPPRRRPRRRSSRPSSRPRRPSRRRPRSRPSRPSRRSPPRPRRRSPRSSSRPRRRPPSRRRRPPSRSRRRPRPRPRPPRRSRRPSRPPSRRRSRRSRRSPSRPRPSPSSRRSPSPSRPRRRPPRSRSPSPPRRPRSRPPSSSRPSPRRPSSSPRRSRRSRRSRSPSSSSRSSPPRRRRPRRRSPSRSPRSSPRSPSPRPRRRPPRPPRPPPSRRRRSSPRRSRRRPRRRSSRRPSRPPRSPPSPPPSPSPSPPSSPRRR...

output:

P

result:

wrong answer 1st lines differ - expected: 'R', found: 'P'