public void ArgumentOutOfRangeInSetGetTest([Values(-1, 10)] int i) { var lst = new LazySegmentTree <int, int>(10, new SimpleOracle()); Assert.Throws <ArgumentOutOfRangeException>(() => lst.Set(i, 1)); Assert.Throws <ArgumentOutOfRangeException>(() => lst.Get(i)); }
public void QueryNaiveTest([Range(1, 30)] int n) { for (var ph = 0; ph < 10; ph++) { var lst = new LazySegmentTree <Monoid, Map>(n, new Oracle()); var timeManager = new TimeManager(n); for (var i = 0; i < n; i++) { lst.Set(i, new Monoid(i, i + 1, -1)); } var now = 0; for (var q = 0; q < 3000; q++) { var ty = Utilities.RandomInteger(0, 3); var(l, r) = Utilities.RandomPair(0, n); switch (ty) { case 0: { var result = lst.Query(l, r); Assert.That(result.L, Is.EqualTo(l)); Assert.That(result.R, Is.EqualTo(r)); Assert.That(result.Time, Is.EqualTo(timeManager.Query(l, r))); break; } case 1: { var result = lst.Get(l); Assert.That(result.L, Is.EqualTo(l)); Assert.That(result.L + 1, Is.EqualTo(l + 1)); Assert.That(result.Time, Is.EqualTo(timeManager.Query(l, l + 1))); break; } case 2: now++; lst.Apply(l, r, new Map(now)); timeManager.Action(l, r, now); break; case 3: now++; lst.Apply(l, new Map(now)); timeManager.Action(l, l + 1, now); break; default: throw new InvalidOperationException(); } } } }
public static void Solve() { var(N, Q) = Scanner.Scan <int, int>(); var st = new LazySegmentTree <Monoid, int>(N * 2, new Oracle()); while (Q-- > 0) { var(t, k) = Scanner.Scan <int, int>(); if (t == 1) { k--; var x = st.Get(k).Value; if (x % 2 == 1) { k = N * 2 - 1 - k; } Console.WriteLine(k + 1); } else { st.Apply(N - k, N + k, 1); } } }