Created
April 14, 2020 02:25
-
-
Save theoremoon/60db55338b9960001a9ec84d97135990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv, | |
std.typecons, std.math, std.container, std.format, std.numeric; | |
alias T = Tuple!(long, "time", long, "value"); | |
class Segtree | |
{ | |
private: | |
T[] xs; | |
long size; | |
public: | |
this(long size) | |
{ | |
long i = 1; | |
while (i <= size) | |
{ | |
i *= 2; | |
} | |
this.size = size; | |
this.xs = new T[](i * 2); | |
} | |
this(long size, T init) | |
{ | |
this(size); | |
this.xs.fill(init); | |
} | |
void update(long l, long r, T x) | |
{ | |
l += this.size; | |
r += this.size; | |
while (l < r) | |
{ | |
if (l % 2 == 1) | |
{ | |
this.xs[l] = x; | |
l++; | |
} | |
l /= 2; | |
if (r % 2 == 1) | |
{ | |
this.xs[r - 1] = x; | |
r--; | |
} | |
r /= 2; | |
} | |
} | |
T find(long i) | |
{ | |
i += this.size; | |
auto ret = this.xs[i]; | |
while (true) | |
{ | |
i /= 2; | |
if (i == 0) | |
{ | |
break; | |
} | |
if (xs[i].time > ret.time) | |
{ | |
ret = xs[i]; | |
} | |
} | |
return ret; | |
} | |
} | |
void main(string[] args) | |
{ | |
long n, q; | |
readf("%d %d\n", &n, &q); | |
auto seg = new Segtree(n, T(-1, (1 << 31) - 1)); | |
long cmd, s, t, x; | |
foreach (i; 0 .. q) | |
{ | |
readf("%d ", &cmd); | |
if (cmd == 0) | |
{ | |
readf("%d %d %d\n", &s, &t, &x); | |
seg.update(s, t + 1, T(i, x)); | |
} | |
else | |
{ | |
readf("%d\n", &x); | |
writeln(seg.find(x).value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment