結果
問題 | No.2540 同値性判定 |
ユーザー |
![]() |
提出日時 | 2023-06-19 04:19:53 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 943 ms / 2,500 ms |
コード長 | 48,387 bytes |
コンパイル時間 | 5,843 ms |
コンパイル使用メモリ | 99,572 KB |
実行使用メモリ | 65,680 KB |
最終ジャッジ日時 | 2024-10-08 06:38:00 |
合計ジャッジ時間 | 39,297 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 TLE * 2 |
ソースコード
package yukicoder_9568;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.util.Arrays;import java.util.BitSet;import java.util.HashSet;import java.util.NoSuchElementException;public class Main {public static void main(String[] args) {new Main();}public Main() {InputChecker ic = new InputChecker(System.in);java.io.PrintWriter out = new java.io.PrintWriter(System.out);solve(ic, out);out.flush();}/** 命題変数の真偽を一つ固定する。* この時、どの命題についてもその命題が真か偽かは確定する。* 命題をfとすると、f(P0, …, P5)=命題の真偽、という形** さて、この時に各演算がどのように作用するか考える。* OYが確定していることから、ある関数g_{Ox}(f)が存在して、g_{Ox}(f) = fOxとなる* f, xの真偽は0と1の二通りだから、g_{Ox}は2次元ベクトルとなり、このようなものは4状態しか取らないね* ところで変換行列ってモノイドで、合成可能ですね*/enum Operator {LAND, LOR, RIGHTARROW;/*** 命題と論理演算から定まる作用関数を返します。* @param Y この時点でのX_hの値* @return 作用関数*/BitFunction getFunction(long val) {switch(this) {case LAND:return BitFunction.and(val);case LOR:return BitFunction.or(val);case RIGHTARROW:return BitFunction.imply(val);}throw new AssertionError();}static Operator getOperator(String operator) {switch(operator) {case "land":return Operator.LAND;case "lor":return Operator.LOR;case "Rightarrow":return Operator.RIGHTARROW;}throw new AssertionError();}}class Query {int h;Operator o;int l, r, l2, r2;Query(InputChecker ic, int N) {h = ic.nextInt(0, N - 1);ic.nextChar(' ');o = Operator.getOperator(ic.next(CharSet.ALPHABET));ic.nextChar(' ');l = ic.nextInt(0, N - 1);ic.nextChar(' ');r = ic.nextInt(l, N - 1) + 1;ic.nextChar(' ');l2 = ic.nextInt(0, N - 1);ic.nextChar(' ');r2 = ic.nextInt(l2, N - 1) + 1;// if (r2 - l2 > 1000) throw new AssertionError();ic.readNewLine();}}/** 基本方針* 1. 全体の命題変数の真偽をそれぞれ固定し、その場合の真偽を解く* 従って、同じ問題を2^6 = 64回解くことになる** 命題変数が決め打たれている時、真偽も分かるので0,1の2状態のみ管理すれば良い* すると、問題は以下の様に考えることができる** 0,1で表された長さNの配列が与えられます* 以下のクエリを捌いてください* 1. X_hの値を取得し、X_h及び追加で与えられた文字列oに応じてどれかの区間作用が発生する* ・区間を0にする* ・区間を1にする* ・区間を反転する* 2. 区間のそれぞれの0,1の値を取得する、長さは最大でL** さて、区間作用1点取得のクエリをO(A)/O(B)で捌けるとすると、計算量はクエリごとにO(A+LB)* また、区間作用1点取得といえばセグ木や平方分割が有名だが、セグ木だとO(LlogN)、平方分割だとO(L+√N)* ここでLは√Nより大きい(10^3)から、平方分割を書いた方が得か** 作用だが、作用行列を考えれば4状態あれば十分であることが分かる* 0の時にxを返す、1の時にyを返すを持った行列(x, y)に対して作用を考えると、全部作用行列になるので* (0, 0)=0, (0, 1)=e, (1, 0)=~, (1, 1)=1として表す* この時、左辺を左、右辺を上に書く行列だと以下の様になる* \ 0 1 e ~* 0 0 0 0 0* 1 1 1 1 1* e 0 1 e ~* ~ 1 0 ~ e* さて、これを良い感じにエンコードしたい** この方針だとTLEするか……ちゃんと64並列で解こうね** ということで、ちゃんとand, or, notを解く* xに対して作用する関数f_{a, b}=(x&a)^bを定義* この時、結果は以下の様になる* (0, 0)→0* (0, 1)→1* (1, 0)→x* (1, 1)→!x* つまり、全てのパターンを網羅している* g_{c, d}∘f_{a, b} = h_{a&c, (b&c)^d}で合成関数も定義できるので勝ち*/public void solve(InputChecker ic, java.io.PrintWriter out) {int N = ic.nextInt(1, 1_000_000);ic.nextChar(' ');int Q = ic.nextInt(1, 100_000);ic.readNewLine();Query[] query = new Query[Q];for (int i = 0;i < Q;++ i) query[i] = new Query(ic, N);ic.checkEOF();BitSet ans = solve(N, query);for (int i = 0;i < Q;++ i) {out.println(ans.get(i) ? "Yes" : "No");}}static final int c = 6; // 命題変数の種類/*** 命題変数の真偽をPを用いて定めた時の結果をqueryに格納します。* @param N 配列長* @param query クエリ* @return 答えを格納したBitSet*/BitSet solve(int N, Query[] query) {LongDualSqrtDecomposition<BitFunction> X;{long[] x = new long[N];long[] test = new long[c];for (int i = 0;i < c;++ i) {for (int j = 0;j < 64;++ j) if ((j >> i & 1) != 0) test[i] |= 1L << j;}for (int i = 0;i < N;++ i) x[i] = test[i % c];X = LongDualSqrtDecomposition.create(x, BitFunction.composition());}BitSet result = new BitSet(query.length);for (int i = 0;i < query.length;++ i) {Query q = query[i];BitFunction operator = q.o.getFunction(X.get(q.h)); // 今回の演算X.apply(q.l, q.r, operator);HashSet<Long> set = new HashSet<>(q.r2 - q.l2, 1);X.foreach(q.l2, q.r2, (j, v) -> set.add(v));result.set(i, set.size() != q.r2 - q.l2);}return result;}public static int exponent10(int n, int e) {return n * pow(10, e);}public static long exponent10L(int n, int e) {return n * pow(10L, e);}public static int pow(int a, int b) {int ans = 1;for (int mul = a;b > 0;b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul;return ans;}public static long pow(long a, long b) {long ans = 1;for (long mul = a;b > 0;b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul;return ans;}public static class CharSet {private final BitSet set = new BitSet(256);public void add(char... c) {for (char i : c) set.set(i);}public void add(CharSet... s) {for (CharSet i : s) set.or(i.set);}public boolean contains(char... c) {for (char i : c) if (!set.get(i)) return false;return true;}public boolean contains(String s) {return contains(s.toCharArray());}private static final class Chars extends CharSet {public Chars(char... c) {super.add(c);}public Chars(CharSet... s) {super.add(s);}@Overridepublic void add(char... c) {throw new UnsupportedOperationException();}@Overridepublic void add(CharSet... s) {throw new UnsupportedOperationException();}}public static final CharSet NUMBER = new Chars('0','1','2','3','4','5','6','7','8','9');public static final CharSet LOWER = new Chars('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');public static final CharSet UPPER = new Chars('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');public static final CharSet ALPHABET = new Chars(LOWER, UPPER);}public static class InputChecker {private InputStream in;private final byte[] buffer = new byte[1024];private final byte[] undo = new byte[1024];private int undoSize = 0;private int read = 0;private int length = 0;public InputChecker(InputStream in) {this.in = in;}public final void setInputStream(InputStream in) {this.in = in;}public final void setInputStream(File in) {try {this.in = new FileInputStream(in);} catch (FileNotFoundException e) {e.printStackTrace();}}private boolean hasNextByte() {if (undoSize > 0) return true;if (read < length) return true;read = 0;try {length = in.read(buffer);} catch (IOException e) {e.printStackTrace();}return length > 0;}private byte readByte() {if (hasNextByte()) return undoSize > 0 ? undo[--undoSize] : buffer[read++];throw new NoSuchElementException();}private void undo(byte b) {undo[undoSize ++] = b;}private void undo(char c) {if ((c & 0xFF80) == 0) {undo((byte)c);return;}undo((byte)(c & 0x3F | 0x80));if ((c & 0xF800) == 0) {undo((byte)(c >> 6 & 0x1F | 0xC0));} else {undo((byte)(c >> 6 & 0x3F | 0x80));undo((byte)(c >> 12 | 0xE0));}}public final boolean hasNext() {return hasNextByte();}public final char nextChar() {byte b = readByte();if ((b & 0x80) == 0) return (char)b;if ((b & 0x20) == 0) return (char)((b & 0x1F) << 6 | readByte() & 0x3F);return (char)((b & 0xF) << 12 | (readByte() & 0x3F) << 6 | readByte() & 0x3F);}public final char nextChar(char estimate) {char c = nextChar();if (estimate == c) return estimate;undo(c);throw new AssertionError();}public final char nextChar(CharSet estimate) {char c = nextChar();if (estimate.contains(c)) return c;undo(c);throw new AssertionError();}public final void readNewLine() {char c = nextChar();if (c == '\r') {c = nextChar();if (c != '\n') undo(c);return;} else if (c == '\n') return;undo(c);throw new AssertionError();}public final void checkEOF() {if (hasNextByte()) throw new AssertionError();}public final String next(CharSet contains) {StringBuilder sb = new StringBuilder();try {do {char c = nextChar();if (!contains.contains(c)) {undo(c);return sb.toString();}sb.append(c);} while(true);} catch (NoSuchElementException e) {if (sb.length() <= 0) throw new AssertionError();return sb.toString();}}public final int nextInt() {byte b = readByte();int n = 0;if (b == '-') {if (!isNumber(b = readByte())) {undo(b);throw new NumberFormatException();}try {if (b == '0') {if (!isNumber(b = readByte())) {undo(b);return 0;}throw new NumberFormatException();}do n = Math.addExact(Math.multiplyExact(n, 10), '0' - b); while(isNumber(b = readByte()));undo(b);} catch (NoSuchElementException e) {}return n;}if (!isNumber(b)) {undo(b);throw new NumberFormatException();}try {if (b == '0') {if (!isNumber(b = readByte())) {undo(b);return 0;}throw new NumberFormatException();}do n = Math.addExact(Math.multiplyExact(n, 10), b - '0'); while(isNumber(b = readByte()));undo(b);} catch (NoSuchElementException e) {}return n;}public final int nextInt(int min, int max) {int n = nextInt();if (min <= n && n <= max) return n;throw new NumberFormatException();}private static boolean isNumber(byte c) {return '0' <= c && c <= '9';}public final long nextLong() {byte b = readByte();long n = 0;if (b == '-') {if (!isNumber(b = readByte())) {undo(b);throw new NumberFormatException();}try {if (b == '0') {if (!isNumber(b = readByte())) {undo(b);return 0;}throw new NumberFormatException();}do n = Math.addExact(Math.multiplyExact(n, 10), '0' - b); while(isNumber(b = readByte()));undo(b);} catch (NoSuchElementException e) {}return n;}if (!isNumber(b)) {undo(b);throw new NumberFormatException();}try {if (b == '0') {if (!isNumber(b = readByte())) {undo(b);return 0;}throw new NumberFormatException();}do n = Math.addExact(Math.multiplyExact(n, 10), b - '0'); while(isNumber(b = readByte()));undo(b);} catch (NoSuchElementException e) {}return n;}public final long nextLong(long min, long max) {long n = nextLong();if (min <= n && n <= max) return n;throw new NumberFormatException();}public final double nextDouble() {StringBuilder sb = new StringBuilder();byte b = readByte();if (b == '-') {sb.append(b);b = readByte();}if (b == '0') {sb.append(b);b = readByte();} else {while(isNumber(b)) {sb.append(b);b = readByte();}}if (b == '.') {sb.append(b);b = readByte();while(isNumber(b)) {sb.append(b);b = readByte();}}if (b == 'e' || b == 'E') {sb.append(b);b = readByte();if (b == '-' || b == '+') {sb.append(b);b = readByte();}while(isNumber(b)) {sb.append(b);b = readByte();}}undo(b);return Double.parseDouble(sb.toString());}}}class BitFunction implements LongEndoMorphism {final long and, xor;private BitFunction(long and, long xor) {this.and = and;this.xor = xor;}@Overridepublic long applyAsLong(long operand) {return operand & and ^ xor;}public BitFunction andThen(BitFunction after) {return new BitFunction(and & after.and, xor & after.and ^ after.xor);}public BitFunction compose(BitFunction before) {return new BitFunction(before.and & and, before.xor & and ^ xor);}public static BitFunction identity() {return new BitFunction(-1L, 0L);}public static Monoid<BitFunction> composition() {return new Monoid<BitFunction>() {@Overridepublic BitFunction apply(BitFunction t, BitFunction u) {return u.andThen(t);}@Overridepublic BitFunction identity() {return BitFunction.identity();}};}public static BitFunction and(long and) {return new BitFunction(and, 0L);}public static BitFunction xor(long xor) {return new BitFunction(-1L, xor);}public static BitFunction or(long or) {return new BitFunction(~or, or);}public static BitFunction not() {return new BitFunction(-1L, -1L);}public static BitFunction nand(long and) {return new BitFunction(and, -1L);}public static BitFunction nor(long or) {return new BitFunction(~or, ~or);}public static BitFunction imply(long consequent) {return new BitFunction(~consequent, -1L);}public static BitFunction xnor(long xor) {return new BitFunction(-1L, ~xor);}}class LongDualSqrtDecomposition<M extends LongEndoMorphism> {private final Monoid<M> composition;private final int bucket;private final Object[] top;private final long[] bottom;private final M identity;LongDualSqrtDecomposition(long[] array, Monoid<M> composition, int bucket) {this.composition = composition;identity = composition.identity();bottom = array.clone();top = new Object[array.length / bucket];Arrays.fill(top, identity);this.bucket = bucket;}@SuppressWarnings("unchecked")private M getTop(int index) {return (M) top[index];}private void lazy(int topIndex) {if (0 > topIndex || topIndex >= top.length) return;M apply = getTop(topIndex);top[topIndex] = identity;for (int l = topIndex * bucket, r = l + bucket;l < r;++ l) bottom[l] = apply.applyAsLong(bottom[l]);}public void apply(int p, M f) {lazy(p / bucket);bottom[p] = f.applyAsLong(bottom[p]);}public void apply(int l, int r, M f) {int lTop = (l + bucket - 1) / bucket;int rTop = r / bucket;if (lTop >= rTop) {if (lTop == rTop) lazy(lTop - 1);lazy(rTop);for (int i = l;i < r;++ i) bottom[i] = f.applyAsLong(bottom[i]);return;}int rBottom = lTop * bucket;int lBottom = rTop * bucket;lazy(lTop - 1);lazy(rTop);for (int i = l;i < rBottom;++ i) bottom[i] = f.applyAsLong(bottom[i]);for (int i = lBottom;i < r;++ i) bottom[i] = f.applyAsLong(bottom[i]);for (int i = lTop;i < rTop;++ i) top[i] = composition.apply(f, getTop(i));}public void set(int p, long val) {lazy(p / bucket);bottom[p] = val;}public long get(int p) {lazy(p / bucket);return bottom[p];}public long[] get(int l, int r) {int lTop = l / bucket;int rTop = (r + bucket - 1) / bucket;for (int i = lTop;i < rTop;++ i) lazy(i);return Arrays.copyOfRange(bottom, l, r);}public void foreach(int l, int r, LongIndexableConsumer action) {int lTop = l / bucket;int rTop = (r + bucket - 1) / bucket;for (int i = lTop;i < rTop;++ i) lazy(i);for (int i = l;i < r;++ i) action.accept(i, bottom[i]);}public static <M extends LongEndoMorphism> LongDualSqrtDecomposition<M> create(long[] array, Monoid<M> composition, int bucket) {return new LongDualSqrtDecomposition<>(array, composition, bucket);}public static <M extends LongEndoMorphism> LongDualSqrtDecomposition<M> create(long[] array, Monoid<M> composition) {return new LongDualSqrtDecomposition<>(array, composition, (int)Math.max(1, Math.sqrt(array.length)));}}interface IndexableConsumer<E> {public void accept(int index, E value);}interface IntIndexableConsumer extends IndexableConsumer<Integer> {public void acceptAsInt(int index, int value);@Overridepublic default void accept(int index, Integer value) {acceptAsInt(index, value);}}interface LongIndexableConsumer extends IndexableConsumer<Long> {public void acceptAsLong(int index, long value);@Overridepublic default void accept(int index, Long value) {acceptAsLong(index, value);}}interface DoubleIndexableConsumer extends IndexableConsumer<Double> {public void acceptAsDouble(int index, double value);@Overridepublic default void accept(int index, Double value) {acceptAsDouble(index, value);}}interface LongMonoid extends Monoid<Long>, LongAssociative, LongUnital {@Overridepublic default long hyperAsLong(long element, int repeat) {if (repeat < 0) throw new IllegalArgumentException("undefined operation");long ret = identityAsLong();for (long mul = element;repeat > 0;repeat >>= 1, mul = applyAsLong(mul, mul)) if ((repeat & 1) != 0) ret = applyAsLong(ret, mul);return ret;}@Overridepublic default long hyperAsLong(long element, long repeat) {if (repeat < 0) throw new IllegalArgumentException("undefined operation");long ret = identityAsLong();for (long mul = element;repeat > 0;repeat >>= 1, mul = applyAsLong(mul, mul)) if ((repeat & 1) != 0) ret = applyAsLong(ret, mul);return ret;}@Overridedefault Long hyper(Long element, int repeat) {return hyperAsLong(element, repeat);}@Overridedefault Long hyper(Long element, long repeat) {return hyperAsLong(element, repeat);}}interface LongEndoMorphism extends LongMorphism, EndoMorphism<Long>, java.util.function.LongUnaryOperator {@Overridepublic default Long apply(Long operand) {return applyAsLong((long) operand);}@Overridepublic default Long apply(long operand) {return applyAsLong(operand);}@Overridepublic default long applyAsLong(Long operand) {return applyAsLong((long) operand);}public default LongEndoMorphism andThen(LongEndoMorphism after) {return s -> after.applyAsLong(applyAsLong(s));}public default LongEndoMorphism compose(LongEndoMorphism before) {return s -> applyAsLong(before.applyAsLong(s));}public static LongEndoMorphism identity() {return t -> t;}public static Monoid<LongEndoMorphism> composition() {return new Monoid<LongEndoMorphism>() {@Overridepublic LongEndoMorphism apply(LongEndoMorphism t, LongEndoMorphism u) {return u.andThen(t);}@Overridepublic LongEndoMorphism identity() {return LongEndoMorphism.identity();}};}}interface Monoid<T> extends Associative<T>, Unital<T> {@Overridepublic default T hyper(T element, int repeat) {if (repeat < 0) throw new IllegalArgumentException("undefined operation");T ret = identity();for (T mul = element;repeat > 0;repeat >>= 1, mul = apply(mul, mul)) if ((repeat & 1) != 0) ret = apply(ret, mul);return ret;}@Overridepublic default T hyper(T element, long repeat) {if (repeat < 0) throw new IllegalArgumentException("undefined operation");T ret = identity();for (T mul = element;repeat > 0;repeat >>= 1, mul = apply(mul, mul)) if ((repeat & 1) != 0) ret = apply(ret, mul);return ret;}}interface LongAssociative extends Associative<Long>, LongMagma{@Overridepublic default Long apply(Long t, Long u) {return applyAsLong(t, u);}@Overridepublic default Long hyper(Long element, int repeat) {return hyperAsLong(element, repeat);}@Overridepublic default Long hyper(Long element, long repeat) {return hyperAsLong(element, repeat);}public default long hyperAsLong(long element, int repeat) {if (repeat < 1) throw new IllegalArgumentException("undefined operation");long ret = element;-- repeat;for (long mul = element;repeat > 0;repeat >>= 1, mul = applyAsLong(mul, mul)) if ((repeat & 1) != 0) ret = applyAsLong(ret, mul);return ret;}public default long hyperAsLong(long element, long repeat) {if (repeat < 1) throw new IllegalArgumentException("undefined operation");long ret = element;-- repeat;for (long mul = element;repeat > 0;repeat >>= 1, mul = applyAsLong(mul, mul)) if ((repeat & 1) != 0) ret = applyAsLong(ret, mul);return ret;}}interface LongUnital extends Unital<Long>, LongMagma {@Overridepublic default Long identity() {return identityAsLong();}public long identityAsLong();}interface EndoMorphism<T> extends Morphism<T, T>, java.util.function.UnaryOperator<T> {public default EndoMorphism<T> andThen(EndoMorphism<T> after) {return s -> after.apply(apply(s));}public default EndoMorphism<T> compose(EndoMorphism<T> before) {return s -> apply(before.apply(s));}public static <T> EndoMorphism<T> identity() {return t -> t;}public static <T> Monoid<EndoMorphism<T>> composition() {return new Monoid<EndoMorphism<T>>() {@Overridepublic EndoMorphism<T> apply(EndoMorphism<T> t, EndoMorphism<T> u) {return u.andThen(t);}@Overridepublic EndoMorphism<T> identity() {return EndoMorphism.identity();}};}}interface LongMorphismextends LongToObjMorphism<Long>, ObjToLongMorphism<Long>, java.util.function.LongUnaryOperator {@Overridepublic default Long apply(Long operand) {return applyAsLong((long) operand);}@Overridepublic default Long apply(long operand) {return applyAsLong(operand);}@Overridepublic default long applyAsLong(Long operand) {return applyAsLong((long) operand);}@Overridepublic default LongToIntMorphism andThen(java.util.function.LongToIntFunction after) {return s -> after.applyAsInt(applyAsLong(s));}@Overridepublic default LongMorphism andThen(java.util.function.LongUnaryOperator after) {return s -> after.applyAsLong(applyAsLong(s));}public default LongMorphism andThen(LongMorphism after) {return s -> after.applyAsLong(applyAsLong(s));}@Overridepublic default LongToDoubleMorphism andThen(java.util.function.LongToDoubleFunction after) {return s -> after.applyAsDouble(applyAsLong(s));}@Overridepublic default <T> LongToObjMorphism<T> andThen(java.util.function.LongFunction<? extends T> after) {return s -> after.apply(applyAsLong(s));}@Overridepublic default IntToLongMorphism compose(java.util.function.IntToLongFunction before) {return s -> applyAsLong(before.applyAsLong(s));}@Overridepublic default LongMorphism compose(java.util.function.LongUnaryOperator before) {return s -> applyAsLong(before.applyAsLong(s));}public default LongMorphism compose(LongMorphism before) {return s -> applyAsLong(before.applyAsLong(s));}@Overridepublic default DoubleToLongMorphism compose(java.util.function.DoubleToLongFunction before) {return s -> applyAsLong(before.applyAsLong(s));}@Overridepublic default <S> ObjToLongMorphism<S> compose(java.util.function.ToLongFunction<? super S> before) {return s -> applyAsLong(before.applyAsLong(s));}public static Associative<LongMorphism> composition() {return (t, u) -> t.andThen(u);}}interface Associative<T> extends Magma<T> {public default T hyper(T element, int repeat) {if (repeat < 1) throw new IllegalArgumentException("undefined operation");T ret = element;--repeat;for (T mul = element; repeat > 0; repeat >>= 1, mul = apply(mul, mul))if ((repeat & 1) != 0) ret = apply(ret, mul);return ret;}public default T hyper(T element, long repeat) {if (repeat < 1) throw new IllegalArgumentException("undefined operation");T ret = element;--repeat;for (T mul = element; repeat > 0; repeat >>= 1, mul = apply(mul, mul))if ((repeat & 1) != 0) ret = apply(ret, mul);return ret;}}interface Unital<T> extends Magma<T> {public T identity();}interface LongMagma extends Magma<Long>, java.util.function.LongBinaryOperator {@Overridepublic default EndoMorphism<Long> partial(Long bind) {return partialAsLong(bind);}public default LongEndoMorphism partialAsLong(long bind) {return t -> applyAsLong(bind, t);}}interface Morphism<S, T> extends java.util.function.Function<S, T>{@Overridepublic default <U> Morphism<S, U> andThen(java.util.function.Function<? super T, ? extends U> after) {return s -> after.apply(apply(s));}@Overridepublic default <U> Morphism<U,T> compose(java.util.function.Function<? super U,? extends S> before) {return s -> apply(before.apply(s));}public static <T> Associative<Morphism<? super T, T>> composition() {return (t, u) -> t.andThen(u);}}interface LongToObjMorphism<T> extends Morphism<Long, T>, java.util.function.LongFunction<T> {@Overridepublic default T apply(Long operand) {return apply((long) operand);}public default LongToIntMorphism andThen(java.util.function.ToIntFunction<? super T> after) {return s -> after.applyAsInt(apply(s));}public default LongMorphism andThen(java.util.function.ToLongFunction<? super T> after) {return s -> after.applyAsLong(apply(s));}public default LongToDoubleMorphism andThen(java.util.function.ToDoubleFunction<? super T> after) {return s -> after.applyAsDouble(apply(s));}@Overridepublic default <U> LongToObjMorphism<U> andThen(java.util.function.Function<? super T, ? extends U> after) {return s -> after.apply(apply(s));}public default IntToObjMorphism<T> compose(java.util.function.IntToLongFunction before) {return s -> apply(before.applyAsLong(s));}public default LongToObjMorphism<T> compose(java.util.function.LongUnaryOperator before) {return s -> apply(before.applyAsLong(s));}public default DoubleToObjMorphism<T> compose(java.util.function.DoubleToLongFunction before) {return s -> apply(before.applyAsLong(s));}public default <S> Morphism<S, T> compose(java.util.function.ToLongFunction<? super S> before) {return s -> apply(before.applyAsLong(s));}}interface ObjToLongMorphism<S> extends Morphism<S, Long>, java.util.function.ToLongFunction<S> {@Overridepublic default Long apply(S operand) {return applyAsLong(operand);}public default ObjToIntMorphism<S> andThen(java.util.function.LongToIntFunction after) {return s -> after.applyAsInt(applyAsLong(s));}public default ObjToLongMorphism<S> andThen(java.util.function.LongUnaryOperator after) {return s -> after.applyAsLong(applyAsLong(s));}public default ObjToDoubleMorphism<S> andThen(java.util.function.LongToDoubleFunction after) {return s -> after.applyAsDouble(applyAsLong(s));}public default <T> Morphism<S, T> andThen(java.util.function.LongFunction<? extends T> after) {return s -> after.apply(applyAsLong(s));}public default IntToLongMorphism compose(java.util.function.IntFunction<? extends S> before) {return s -> applyAsLong(before.apply(s));}public default LongMorphism compose(java.util.function.LongFunction<? extends S> before) {return s -> applyAsLong(before.apply(s));}public default DoubleToLongMorphism compose(java.util.function.DoubleFunction<? extends S> before) {return s -> applyAsLong(before.apply(s));}@Overridepublic default <U> ObjToLongMorphism<U> compose(java.util.function.Function<? super U, ? extends S> before) {return s -> applyAsLong(before.apply(s));}}interface LongToIntMorphismextends LongToObjMorphism<Integer>, ObjToIntMorphism<Long>, java.util.function.LongToIntFunction {@Overridepublic default Integer apply(Long operand) {return applyAsInt((long) operand);}@Overridepublic default Integer apply(long operand) {return applyAsInt(operand);}@Overridepublic default int applyAsInt(Long operand) {return applyAsInt((long) operand);}@Overridepublic default LongToIntMorphism andThen(java.util.function.IntUnaryOperator after) {return s -> after.applyAsInt(applyAsInt(s));}@Overridepublic default LongMorphism andThen(java.util.function.IntToLongFunction after) {return s -> after.applyAsLong(applyAsInt(s));}@Overridepublic default LongToDoubleMorphism andThen(java.util.function.IntToDoubleFunction after) {return s -> after.applyAsDouble(applyAsInt(s));}@Overridepublic default <T> LongToObjMorphism<T> andThen(java.util.function.IntFunction<? extends T> after) {return s -> after.apply(applyAsInt(s));}@Overridepublic default IntMorphism compose(java.util.function.IntToLongFunction before) {return s -> applyAsInt(before.applyAsLong(s));}@Overridepublic default LongToIntMorphism compose(java.util.function.LongUnaryOperator before) {return s -> applyAsInt(before.applyAsLong(s));}@Overridepublic default DoubleToIntMorphism compose(java.util.function.DoubleToLongFunction before) {return s -> applyAsInt(before.applyAsLong(s));}@Overridepublic default <S> ObjToIntMorphism<S> compose(java.util.function.ToLongFunction<? super S> before) {return s -> applyAsInt(before.applyAsLong(s));}}interface LongToDoubleMorphismextends LongToObjMorphism<Double>, ObjToDoubleMorphism<Long>, java.util.function.LongToDoubleFunction {@Overridepublic default Double apply(Long operand) {return applyAsDouble((long) operand);}@Overridepublic default Double apply(long operand) {return applyAsDouble(operand);}@Overridepublic default double applyAsDouble(Long operand) {return applyAsDouble((long) operand);}@Overridepublic default LongToIntMorphism andThen(java.util.function.DoubleToIntFunction after) {return s -> after.applyAsInt(applyAsDouble(s));}@Overridepublic default LongMorphism andThen(java.util.function.DoubleToLongFunction after) {return s -> after.applyAsLong(applyAsDouble(s));}@Overridepublic default LongToDoubleMorphism andThen(java.util.function.DoubleUnaryOperator after) {return s -> after.applyAsDouble(applyAsDouble(s));}@Overridepublic default <T> LongToObjMorphism<T> andThen(java.util.function.DoubleFunction<? extends T> after) {return s -> after.apply(applyAsDouble(s));}@Overridepublic default IntToDoubleMorphism compose(java.util.function.IntToLongFunction before) {return s -> applyAsDouble(before.applyAsLong(s));}@Overridepublic default LongToDoubleMorphism compose(java.util.function.LongUnaryOperator before) {return s -> applyAsDouble(before.applyAsLong(s));}@Overridepublic default DoubleMorphism compose(java.util.function.DoubleToLongFunction before) {return s -> applyAsDouble(before.applyAsLong(s));}@Overridepublic default <S> ObjToDoubleMorphism<S> compose(java.util.function.ToLongFunction<? super S> before) {return s -> applyAsDouble(before.applyAsLong(s));}}interface IntToLongMorphismextends IntToObjMorphism<Long>, ObjToLongMorphism<Integer>, java.util.function.IntToLongFunction {@Overridepublic default Long apply(Integer operand) {return applyAsLong((int) operand);}@Overridepublic default Long apply(int operand) {return applyAsLong(operand);}@Overridepublic default long applyAsLong(Integer operand) {return applyAsLong((int) operand);}@Overridepublic default IntMorphism andThen(java.util.function.LongToIntFunction after) {return s -> after.applyAsInt(applyAsLong(s));}@Overridepublic default IntToLongMorphism andThen(java.util.function.LongUnaryOperator after) {return s -> after.applyAsLong(applyAsLong(s));}@Overridepublic default IntToDoubleMorphism andThen(java.util.function.LongToDoubleFunction after) {return s -> after.applyAsDouble(applyAsLong(s));}@Overridepublic default <T> IntToObjMorphism<T> andThen(java.util.function.LongFunction<? extends T> after) {return s -> after.apply(applyAsLong(s));}@Overridepublic default IntToLongMorphism compose(java.util.function.IntUnaryOperator before) {return s -> applyAsLong(before.applyAsInt(s));}@Overridepublic default LongMorphism compose(java.util.function.LongToIntFunction before) {return s -> applyAsLong(before.applyAsInt(s));}@Overridepublic default DoubleToLongMorphism compose(java.util.function.DoubleToIntFunction before) {return s -> applyAsLong(before.applyAsInt(s));}@Overridepublic default <S> ObjToLongMorphism<S> compose(java.util.function.ToIntFunction<? super S> before) {return s -> applyAsLong(before.applyAsInt(s));}}interface DoubleToLongMorphismextends DoubleToObjMorphism<Long>, ObjToLongMorphism<Double>, java.util.function.DoubleToLongFunction {@Overridepublic default Long apply(Double operand) {return applyAsLong((double) operand);}@Overridepublic default Long apply(double operand) {return applyAsLong(operand);}@Overridepublic default long applyAsLong(Double operand) {return applyAsLong((double) operand);}@Overridepublic default DoubleToIntMorphism andThen(java.util.function.LongToIntFunction after) {return s -> after.applyAsInt(applyAsLong(s));}@Overridepublic default DoubleToLongMorphism andThen(java.util.function.LongUnaryOperator after) {return s -> after.applyAsLong(applyAsLong(s));}@Overridepublic default DoubleMorphism andThen(java.util.function.LongToDoubleFunction after) {return s -> after.applyAsDouble(applyAsLong(s));}@Overridepublic default <T> DoubleToObjMorphism<T> andThen(java.util.function.LongFunction<? extends T> after) {return s -> after.apply(applyAsLong(s));}@Overridepublic default IntToLongMorphism compose(java.util.function.IntToDoubleFunction before) {return s -> applyAsLong(before.applyAsDouble(s));}@Overridepublic default LongMorphism compose(java.util.function.LongToDoubleFunction before) {return s -> applyAsLong(before.applyAsDouble(s));}@Overridepublic default DoubleToLongMorphism compose(java.util.function.DoubleUnaryOperator before) {return s -> applyAsLong(before.applyAsDouble(s));}@Overridepublic default <S> ObjToLongMorphism<S> compose(java.util.function.ToDoubleFunction<? super S> before) {return s -> applyAsLong(before.applyAsDouble(s));}}interface Magma<T> extends java.util.function.BinaryOperator<T>{public default EndoMorphism<T> partial(T bind) {return t -> apply(bind, t);}}interface IntToObjMorphism<T> extends Morphism<Integer, T>, java.util.function.IntFunction<T> {@Overridepublic default T apply(Integer operand) {return apply((int) operand);}public default IntMorphism andThen(java.util.function.ToIntFunction<? super T> after) {return s -> after.applyAsInt(apply(s));}public default IntToLongMorphism andThen(java.util.function.ToLongFunction<? super T> after) {return s -> after.applyAsLong(apply(s));}public default IntToDoubleMorphism andThen(java.util.function.ToDoubleFunction<? super T> after) {return s -> after.applyAsDouble(apply(s));}@Overridepublic default <U> IntToObjMorphism<U> andThen(java.util.function.Function<? super T, ? extends U> after) {return s -> after.apply(apply(s));}public default IntToObjMorphism<T> compose(java.util.function.IntUnaryOperator before) {return s -> apply(before.applyAsInt(s));}public default LongToObjMorphism<T> compose(java.util.function.LongToIntFunction before) {return s -> apply(before.applyAsInt(s));}public default DoubleToObjMorphism<T> compose(java.util.function.DoubleToIntFunction before) {return s -> apply(before.applyAsInt(s));}public default <S> Morphism<S, T> compose(java.util.function.ToIntFunction<? super S> before) {return s -> apply(before.applyAsInt(s));}}interface DoubleToObjMorphism<T> extends Morphism<Double, T>, java.util.function.DoubleFunction<T> {@Overridepublic default T apply(Double operand) {return apply((double) operand);}public default DoubleToIntMorphism andThen(java.util.function.ToIntFunction<? super T> after) {return s -> after.applyAsInt(apply(s));}public default DoubleToLongMorphism andThen(java.util.function.ToLongFunction<? super T> after) {return s -> after.applyAsLong(apply(s));}public default DoubleMorphism andThen(java.util.function.ToDoubleFunction<? super T> after) {return s -> after.applyAsDouble(apply(s));}@Overridepublic default <U> DoubleToObjMorphism<U> andThen(java.util.function.Function<? super T, ? extends U> after) {return s -> after.apply(apply(s));}public default IntToObjMorphism<T> compose(java.util.function.IntToDoubleFunction before) {return s -> apply(before.applyAsDouble(s));}public default LongToObjMorphism<T> compose(java.util.function.LongToDoubleFunction before) {return s -> apply(before.applyAsDouble(s));}public default DoubleToObjMorphism<T> compose(java.util.function.DoubleUnaryOperator before) {return s -> apply(before.applyAsDouble(s));}public default <S> Morphism<S, T> compose(java.util.function.ToDoubleFunction<? super S> before) {return s -> apply(before.applyAsDouble(s));}}interface ObjToIntMorphism<S> extends Morphism<S, Integer>, java.util.function.ToIntFunction<S> {@Overridepublic default Integer apply(S operand) {return applyAsInt(operand);}public default ObjToIntMorphism<S> andThen(java.util.function.IntUnaryOperator after) {return s -> after.applyAsInt(applyAsInt(s));}public default ObjToLongMorphism<S> andThen(java.util.function.IntToLongFunction after) {return s -> after.applyAsLong(applyAsInt(s));}public default ObjToDoubleMorphism<S> andThen(java.util.function.IntToDoubleFunction after) {return s -> after.applyAsDouble(applyAsInt(s));}public default <T> Morphism<S, T> andThen(java.util.function.IntFunction<? extends T> after) {return s -> after.apply(applyAsInt(s));}public default IntMorphism compose(java.util.function.IntFunction<? extends S> before) {return s -> applyAsInt(before.apply(s));}public default LongToIntMorphism compose(java.util.function.LongFunction<? extends S> before) {return s -> applyAsInt(before.apply(s));}public default DoubleToIntMorphism compose(java.util.function.DoubleFunction<? extends S> before) {return s -> applyAsInt(before.apply(s));}@Overridepublic default <U> ObjToIntMorphism<U> compose(java.util.function.Function<? super U, ? extends S> before) {return s -> applyAsInt(before.apply(s));}}interface ObjToDoubleMorphism<S> extends Morphism<S, Double>, java.util.function.ToDoubleFunction<S> {@Overridepublic default Double apply(S operand) {return applyAsDouble(operand);}public default ObjToIntMorphism<S> andThen(java.util.function.DoubleToIntFunction after) {return s -> after.applyAsInt(applyAsDouble(s));}public default ObjToLongMorphism<S> andThen(java.util.function.DoubleToLongFunction after) {return s -> after.applyAsLong(applyAsDouble(s));}public default ObjToDoubleMorphism<S> andThen(java.util.function.DoubleUnaryOperator after) {return s -> after.applyAsDouble(applyAsDouble(s));}public default <T> Morphism<S, T> andThen(java.util.function.DoubleFunction<? extends T> after) {return s -> after.apply(applyAsDouble(s));}public default IntToDoubleMorphism compose(java.util.function.IntFunction<? extends S> before) {return s -> applyAsDouble(before.apply(s));}public default LongToDoubleMorphism compose(java.util.function.LongFunction<? extends S> before) {return s -> applyAsDouble(before.apply(s));}public default DoubleMorphism compose(java.util.function.DoubleFunction<? extends S> before) {return s -> applyAsDouble(before.apply(s));}@Overridepublic default <U> ObjToDoubleMorphism<U> compose(java.util.function.Function<? super U, ? extends S> before) {return s -> applyAsDouble(before.apply(s));}}interface IntMorphismextends IntToObjMorphism<Integer>, ObjToIntMorphism<Integer>, java.util.function.IntUnaryOperator {@Overridepublic default Integer apply(Integer operand) {return applyAsInt((int) operand);}@Overridepublic default Integer apply(int operand) {return applyAsInt(operand);}@Overridepublic default int applyAsInt(Integer operand) {return applyAsInt((int) operand);}@Overridepublic default IntMorphism andThen(java.util.function.IntUnaryOperator after) {return s -> after.applyAsInt(applyAsInt(s));}@Overridepublic default IntToLongMorphism andThen(java.util.function.IntToLongFunction after) {return s -> after.applyAsLong(applyAsInt(s));}@Overridepublic default IntToDoubleMorphism andThen(java.util.function.IntToDoubleFunction after) {return s -> after.applyAsDouble(applyAsInt(s));}public default IntMorphism andThen(IntMorphism after) {return s -> after.applyAsInt(applyAsInt(s));}@Overridepublic default <T> IntToObjMorphism<T> andThen(java.util.function.IntFunction<? extends T> after) {return s -> after.apply(applyAsInt(s));}@Overridepublic default IntMorphism compose(java.util.function.IntUnaryOperator before) {return s -> applyAsInt(before.applyAsInt(s));}@Overridepublic default LongToIntMorphism compose(java.util.function.LongToIntFunction before) {return s -> applyAsInt(before.applyAsInt(s));}@Overridepublic default DoubleToIntMorphism compose(java.util.function.DoubleToIntFunction before) {return s -> applyAsInt(before.applyAsInt(s));}public default IntMorphism compose(IntMorphism before) {return s -> applyAsInt(before.applyAsInt(s));}@Overridepublic default <S> ObjToIntMorphism<S> compose(java.util.function.ToIntFunction<? super S> before) {return s -> applyAsInt(before.applyAsInt(s));}public static Associative<IntMorphism> composition() {return (t, u) -> t.andThen(u);}}interface DoubleToIntMorphismextends DoubleToObjMorphism<Integer>, ObjToIntMorphism<Double>, java.util.function.DoubleToIntFunction {@Overridepublic default Integer apply(Double operand) {return applyAsInt((double) operand);}@Overridepublic default Integer apply(double operand) {return applyAsInt(operand);}@Overridepublic default int applyAsInt(Double operand) {return applyAsInt((double) operand);}@Overridepublic default DoubleToIntMorphism andThen(java.util.function.IntUnaryOperator after) {return s -> after.applyAsInt(applyAsInt(s));}@Overridepublic default DoubleToLongMorphism andThen(java.util.function.IntToLongFunction after) {return s -> after.applyAsLong(applyAsInt(s));}@Overridepublic default DoubleMorphism andThen(java.util.function.IntToDoubleFunction after) {return s -> after.applyAsDouble(applyAsInt(s));}@Overridepublic default <T> DoubleToObjMorphism<T> andThen(java.util.function.IntFunction<? extends T> after) {return s -> after.apply(applyAsInt(s));}@Overridepublic default IntMorphism compose(java.util.function.IntToDoubleFunction before) {return s -> applyAsInt(before.applyAsDouble(s));}@Overridepublic default LongToIntMorphism compose(java.util.function.LongToDoubleFunction before) {return s -> applyAsInt(before.applyAsDouble(s));}@Overridepublic default DoubleToIntMorphism compose(java.util.function.DoubleUnaryOperator before) {return s -> applyAsInt(before.applyAsDouble(s));}@Overridepublic default <S> ObjToIntMorphism<S> compose(java.util.function.ToDoubleFunction<? super S> before) {return s -> applyAsInt(before.applyAsDouble(s));}}interface IntToDoubleMorphismextends IntToObjMorphism<Double>, ObjToDoubleMorphism<Integer>, java.util.function.IntToDoubleFunction {@Overridepublic default Double apply(Integer operand) {return applyAsDouble((int) operand);}@Overridepublic default Double apply(int operand) {return applyAsDouble(operand);}@Overridepublic default double applyAsDouble(Integer operand) {return applyAsDouble((int) operand);}@Overridepublic default IntMorphism andThen(java.util.function.DoubleToIntFunction after) {return s -> after.applyAsInt(applyAsDouble(s));}@Overridepublic default IntToLongMorphism andThen(java.util.function.DoubleToLongFunction after) {return s -> after.applyAsLong(applyAsDouble(s));}@Overridepublic default IntToDoubleMorphism andThen(java.util.function.DoubleUnaryOperator after) {return s -> after.applyAsDouble(applyAsDouble(s));}@Overridepublic default <T> IntToObjMorphism<T> andThen(java.util.function.DoubleFunction<? extends T> after) {return s -> after.apply(applyAsDouble(s));}@Overridepublic default IntToDoubleMorphism compose(java.util.function.IntUnaryOperator before) {return s -> applyAsDouble(before.applyAsInt(s));}@Overridepublic default LongToDoubleMorphism compose(java.util.function.LongToIntFunction before) {return s -> applyAsDouble(before.applyAsInt(s));}@Overridepublic default DoubleMorphism compose(java.util.function.DoubleToIntFunction before) {return s -> applyAsDouble(before.applyAsInt(s));}@Overridepublic default <S> ObjToDoubleMorphism<S> compose(java.util.function.ToIntFunction<? super S> before) {return s -> applyAsDouble(before.applyAsInt(s));}}interface DoubleMorphismextends DoubleToObjMorphism<Double>, ObjToDoubleMorphism<Double>, java.util.function.DoubleUnaryOperator {@Overridepublic default Double apply(Double operand) {return applyAsDouble((double) operand);}@Overridepublic default Double apply(double operand) {return applyAsDouble(operand);}@Overridepublic default double applyAsDouble(Double operand) {return applyAsDouble((double) operand);}@Overridepublic default DoubleToIntMorphism andThen(java.util.function.DoubleToIntFunction after) {return s -> after.applyAsInt(applyAsDouble(s));}@Overridepublic default DoubleToLongMorphism andThen(java.util.function.DoubleToLongFunction after) {return s -> after.applyAsLong(applyAsDouble(s));}@Overridepublic default DoubleMorphism andThen(java.util.function.DoubleUnaryOperator after) {return s -> after.applyAsDouble(applyAsDouble(s));}public default DoubleMorphism andThen(DoubleMorphism after) {return s -> after.applyAsDouble(applyAsDouble(s));}public default <T> DoubleToObjMorphism<T> andThen(DoubleToObjMorphism<? extends T> after) {return s -> after.apply(applyAsDouble(s));}@Overridepublic default IntToDoubleMorphism compose(java.util.function.IntToDoubleFunction before) {return s -> applyAsDouble(before.applyAsDouble(s));}@Overridepublic default LongToDoubleMorphism compose(java.util.function.LongToDoubleFunction before) {return s -> applyAsDouble(before.applyAsDouble(s));}@Overridepublic default DoubleMorphism compose(java.util.function.DoubleUnaryOperator before) {return s -> applyAsDouble(before.applyAsDouble(s));}public default DoubleMorphism compose(DoubleMorphism before) {return s -> applyAsDouble(before.applyAsDouble(s));}public default <S> ObjToDoubleMorphism<S> compose(ObjToDoubleMorphism<? super S> before) {return s -> applyAsDouble(before.applyAsDouble(s));}public static Associative<DoubleMorphism> composition() {return (t, u) -> t.andThen(u);}}