結果
問題 | No.2540 同値性判定 |
ユーザー | CuriousFairy315 |
提出日時 | 2023-06-18 20:54:50 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 48,988 bytes |
コンパイル時間 | 4,627 ms |
コンパイル使用メモリ | 100,348 KB |
実行使用メモリ | 142,524 KB |
最終ジャッジ日時 | 2024-10-08 06:40:02 |
合計ジャッジ時間 | 14,016 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 83 ms
58,496 KB |
testcase_01 | AC | 89 ms
51,616 KB |
testcase_02 | AC | 86 ms
51,432 KB |
testcase_03 | AC | 85 ms
51,636 KB |
testcase_04 | AC | 87 ms
51,604 KB |
testcase_05 | AC | 86 ms
51,604 KB |
testcase_06 | AC | 85 ms
51,632 KB |
testcase_07 | AC | 87 ms
51,488 KB |
testcase_08 | AC | 87 ms
51,692 KB |
testcase_09 | AC | 88 ms
51,696 KB |
testcase_10 | AC | 94 ms
51,740 KB |
testcase_11 | WA | - |
testcase_12 | AC | 234 ms
55,600 KB |
testcase_13 | AC | 317 ms
60,312 KB |
testcase_14 | AC | 897 ms
65,072 KB |
testcase_15 | WA | - |
testcase_16 | TLE | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
evil_00.txt | -- | - |
evil_01.txt | -- | - |
evil_02.txt | -- | - |
evil_03.txt | -- | - |
evil_04.txt | -- | - |
evil_05.txt | -- | - |
evil_06.txt | -- | - |
evil_07.txt | -- | - |
evil_08.txt | -- | - |
evil_09.txt | -- | - |
evil_10.txt | -- | - |
evil_11.txt | -- | - |
ソースコード
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.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 作用関数 */ int getFunction(boolean Y) { switch(this) { case LAND: return Y ? BitFunction.UNIT : BitFunction.FALSE; case LOR: return Y ? BitFunction.TRUE : BitFunction.UNIT; case RIGHTARROW: return Y ? BitFunction.TRUE : BitFunction.NOT; } 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; long[] result; 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; ic.readNewLine(); result = new long[r2 - l2]; } } /* * 基本方針 * 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 * さて、これを良い感じにエンコードしたい * */ public void solve(InputChecker ic, java.io.PrintWriter out) { int N = ic.nextInt(1, 1_000_000); ic.nextChar(' '); int Q = ic.nextInt(1, 10_000); ic.readNewLine(); Query[] query = new Query[Q]; for (int i = 0;i < Q;++ i) query[i] = new Query(ic, N); // ic.checkEOF(); for (int P = 0;P < 1 << c;++ P) solve(N, query, P); for (Query q : query) { // out.println(Arrays.toString(q.result)); // TODO out.println(q.result.length != Arrays.stream(q.result).distinct().count() ? "Yes" : "No"); } } static final int c = 6; // 命題変数の種類 /** * 命題変数の真偽をPを用いて定めた時の結果をqueryに格納します。 * @param N 配列長 * @param query クエリ * @param P Pのi-bitが命題P_iの真偽に対応する */ void solve(int N, Query[] query, int P) { BitSet X = new BitSet(N); IntDualSqrtDecomposition function = new IntDualSqrtDecomposition(N, new BitFunction(), 10); for (int j = 0;j < N;++ j) X.set(j, (P >> j % c & 1) != 0); final long test = 1L << P; // 対応するbitの位置(後で使う) for (Query q : query) { X.set(q.h, BitFunction.apply(function.poll(q.h), X.get(q.h))); int operator = q.o.getFunction(X.get(q.h)); // 今回の演算 function.apply(q.l, q.r, operator); long[] result = q.result; final int l = q.l2; function.foreach(q.l2, q.r2, (i, f) -> { if (BitFunction.apply(f, X.get(i))) result[i - l] |= test; }); // if (P < 4) System.out.println(P + ":" + X + "," + operator); // TODO } } class IntDualSqrtDecomposition { IntMonoid composition; int bucket; int[] top; int[] bottom; IntDualSqrtDecomposition(int length, IntMonoid composition, int bucket) { this.composition = composition; bottom = new int[length]; Arrays.fill(bottom, composition.identityAsInt()); top = new int[length / bucket]; Arrays.fill(top, composition.identityAsInt()); this.bucket = bucket; } IntDualSqrtDecomposition(int length, IntMonoid composition) { this(length, composition, Math.max(1, (int)Math.sqrt(length))); } private void lazy(int topIndex) { if (0 > topIndex || topIndex >= top.length) return; int apply = top[topIndex]; top[topIndex] = composition.identityAsInt(); for (int l = topIndex * bucket, r = l + bucket;l < r;++ l) bottom[l] = composition.applyAsInt(apply, bottom[l]); } /** * p番目の要素に関数fを作用させます。 * @param p 作用させる要素の位置 * @param f 作用させる関数 */ public void apply(int p, int f) { lazy(p / bucket); bottom[p] = composition.applyAsInt(f, bottom[p]); } /** * 区間[l, r)に関数fを作用させます。 * @param l 区間の左端(これを含まない) * @param r 区間の右端(これを含む) * @param f 作用させる関数 */ public void apply(int l, int r, int 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] = composition.applyAsInt(f, 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] = composition.applyAsInt(f, bottom[i]); for (int i = lBottom;i < r;++ i) bottom[i] = composition.applyAsInt(f, bottom[i]); for (int i = lTop;i < rTop;++ i) top[i] = composition.applyAsInt(f, top[i]); } /** * p番目の要素に作用する関数をfにします。 * @param p 作用させる要素の位置 * @param f 作用させる関数 */ public void set(int p, int f) { lazy(p / bucket); bottom[p] = f; } /** * p番目の要素に作用する関数を取得します。 * @param p 取得する関数の位置 * @return 作用する関数 */ public int get(int p) { lazy(p / bucket); return bottom[p]; } /** * 区間[l, r)に作用する関数を取得します。 * @param l 区間の左端(これを含まない) * @param r 区間の右端(これを含む) * @return 作用する関数 */ public int[] get(int l, int r) { int lTop = l / bucket; int rTop = (r - 1) / bucket; for (int i = lTop;i < rTop;++ i) lazy(i); return Arrays.copyOfRange(bottom, l, r); } /** * p番目の要素に作用する関数を取得し、その後単位元に差し替えます。 * @param p 取得する関数の位置 * @return 作用する関数 */ public int poll(int p) { lazy(p / bucket); int ret = bottom[p]; bottom[p] = composition.identityAsInt(); return ret; } /** * 区間[l, r)に作用する関数を取得し、その後単位元に差し替えます。 * @param l 区間の左端(これを含まない) * @param r 区間の右端(これを含む) * @return 作用する関数 */ public int[] poll(int l, int r) { int lTop = l / bucket; int rTop = (r - 1) / bucket; for (int i = lTop;i < rTop;++ i) lazy(i); int[] ret = Arrays.copyOfRange(bottom, l, r); Arrays.fill(bottom, l, r, composition.identityAsInt()); return ret; } /** * 区間[l, r)に順に処理を適用します。 * @param l 区間の左端(これを含まない) * @param r 区間の右端(これを含む) * @param action 各要素に対して実行されるアクション */ public void foreach(int l, int r, IntIndexableConsumer action) { int lTop = l / bucket; int rTop = (r - 1) / bucket; for (int i = lTop;i < rTop;++ i) lazy(i); for (int i = l;i < r;++ i) action.acceptAsInt(i, bottom[i]); } } 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); } @Override public void add(char... c) { throw new UnsupportedOperationException(); } @Override public 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 IntMonoid { static final int FALSE = 0; static final int TRUE = 1; static final int UNIT = 2; static final int NOT = 3; @Override public int applyAsInt(int after, int before) { switch(after) { case FALSE: case TRUE: return after; case UNIT: return before; case NOT: return before ^ 1; } throw new AssertionError(); } @Override public int identityAsInt() { return UNIT; } static boolean apply(int operator, boolean argument) { switch(operator) { case FALSE: return false; case TRUE: return true; case UNIT: return argument; case NOT: return !argument; } throw new AssertionError(); } } interface IndexableConsumer<E> { public void accept(int index, E value); } interface IntIndexableConsumer extends IndexableConsumer<Integer> { public void acceptAsInt(int index, int value); @Override public default void accept(int index, Integer value) { acceptAsInt(index, value); } } interface LongIndexableConsumer extends IndexableConsumer<Long> { public void acceptAsLong(int index, long value); @Override public default void accept(int index, Long value) { acceptAsLong(index, value); } } interface DoubleIndexableConsumer extends IndexableConsumer<Double> { public void acceptAsDouble(int index, double value); @Override public default void accept(int index, Double value) { acceptAsDouble(index, value); } } interface IntMonoid extends Monoid<Integer>, IntAssociative, IntUnital { @Override public default Integer apply(Integer t, Integer u) { return applyAsInt(t, u); } @Override public default Integer hyper(Integer element, int repeat) { return hyperAsInt(element, repeat); } @Override public default Integer hyper(Integer element, long repeat) { return hyperAsInt(element, repeat); } @Override public default int hyperAsInt(int element, int repeat) { if (repeat < 0) throw new IllegalArgumentException("undefined operation"); int ret = identityAsInt(); for (int mul = element;repeat > 0;repeat >>= 1, mul = applyAsInt(mul, mul)) if ((repeat & 1) != 0) ret = applyAsInt(ret, mul); return ret; } @Override public default int hyperAsInt(int element, long repeat) { if (repeat < 0) throw new IllegalArgumentException("undefined operation"); int ret = identityAsInt(); for (int mul = element;repeat > 0;repeat >>= 1, mul = applyAsInt(mul, mul)) if ((repeat & 1) != 0) ret = applyAsInt(ret, mul); return ret; } } interface Monoid<T> extends Associative<T>, Unital<T> { @Override public 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; } @Override public 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 IntAssociative extends Associative<Integer>, IntMagma{ @Override public default Integer apply(Integer t, Integer u) { return applyAsInt(t, u); } @Override public default Integer hyper(Integer element, int repeat) { return hyperAsInt(element, repeat); } @Override public default Integer hyper(Integer element, long repeat) { return hyperAsInt(element, repeat); } public default int hyperAsInt(int element, int repeat) { if (repeat < 1) throw new IllegalArgumentException("undefined operation"); int ret = element; -- repeat; for (int mul = element;repeat > 0;repeat >>= 1, mul = applyAsInt(mul, mul)) if ((repeat & 1) != 0) ret = applyAsInt(ret, mul); return ret; } public default int hyperAsInt(int element, long repeat) { if (repeat < 1) throw new IllegalArgumentException("undefined operation"); int ret = element; -- repeat; for (int mul = element;repeat > 0;repeat >>= 1, mul = applyAsInt(mul, mul)) if ((repeat & 1) != 0) ret = applyAsInt(ret, mul); return ret; } } interface IntUnital extends Unital<Integer>, IntMagma { @Override public default Integer apply(Integer t, Integer u) { return applyAsInt(t, u); } @Override public default Integer identity() { return identityAsInt(); } public int identityAsInt(); } 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 IntMagma extends Magma<Integer>, java.util.function.IntBinaryOperator { @Override public default EndoMorphism<Integer> partial(Integer bind) { return partialAsInt(bind); } public default IntEndoMorphism partialAsInt(int bind) { return t -> applyAsInt(bind, t); } } interface Magma<T> extends java.util.function.BinaryOperator<T>{ public default EndoMorphism<T> partial(T bind) { return t -> apply(bind, t); } } 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>>() { @Override public EndoMorphism<T> apply(EndoMorphism<T> t, EndoMorphism<T> u) { return u.andThen(t); } @Override public EndoMorphism<T> identity() { return EndoMorphism.identity(); } }; } } interface IntEndoMorphism extends IntMorphism, EndoMorphism<Integer>, java.util.function.IntUnaryOperator { @Override public default Integer apply(Integer operand) { return applyAsInt((int) operand); } @Override public default Integer apply(int operand) { return applyAsInt(operand); } @Override public default int applyAsInt(Integer operand) { return applyAsInt((int) operand); } public default IntEndoMorphism andThen(IntEndoMorphism after) { return s -> after.applyAsInt(applyAsInt(s)); } public default IntEndoMorphism compose(IntEndoMorphism before) { return s -> applyAsInt(before.applyAsInt(s)); } public static IntEndoMorphism identity() { return t -> t; } public static Monoid<IntEndoMorphism> composition() { return new Monoid<IntEndoMorphism>() { @Override public IntEndoMorphism apply(IntEndoMorphism t, IntEndoMorphism u) { return u.andThen(t); } @Override public IntEndoMorphism identity() { return IntEndoMorphism.identity(); } }; } } interface Morphism<S, T> extends java.util.function.Function<S, T>{ @Override public default <U> Morphism<S, U> andThen(java.util.function.Function<? super T, ? extends U> after) { return s -> after.apply(apply(s)); } @Override public 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 IntMorphism extends IntToObjMorphism<Integer>, ObjToIntMorphism<Integer>, java.util.function.IntUnaryOperator { @Override public default Integer apply(Integer operand) { return applyAsInt((int) operand); } @Override public default Integer apply(int operand) { return applyAsInt(operand); } @Override public default int applyAsInt(Integer operand) { return applyAsInt((int) operand); } @Override public default IntMorphism andThen(java.util.function.IntUnaryOperator after) { return s -> after.applyAsInt(applyAsInt(s)); } @Override public default IntToLongMorphism andThen(java.util.function.IntToLongFunction after) { return s -> after.applyAsLong(applyAsInt(s)); } @Override public 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)); } @Override public default <T> IntToObjMorphism<T> andThen(java.util.function.IntFunction<? extends T> after) { return s -> after.apply(applyAsInt(s)); } @Override public default IntMorphism compose(java.util.function.IntUnaryOperator before) { return s -> applyAsInt(before.applyAsInt(s)); } @Override public default LongToIntMorphism compose(java.util.function.LongToIntFunction before) { return s -> applyAsInt(before.applyAsInt(s)); } @Override public 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)); } @Override public 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 IntToObjMorphism<T> extends Morphism<Integer, T>, java.util.function.IntFunction<T> { @Override public 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)); } @Override public 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 ObjToIntMorphism<S> extends Morphism<S, Integer>, java.util.function.ToIntFunction<S> { @Override public 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)); } @Override public default <U> ObjToIntMorphism<U> compose(java.util.function.Function<? super U, ? extends S> before) { return s -> applyAsInt(before.apply(s)); } } interface IntToLongMorphism extends IntToObjMorphism<Long>, ObjToLongMorphism<Integer>, java.util.function.IntToLongFunction { @Override public default Long apply(Integer operand) { return applyAsLong((int) operand); } @Override public default Long apply(int operand) { return applyAsLong(operand); } @Override public default long applyAsLong(Integer operand) { return applyAsLong((int) operand); } @Override public default IntMorphism andThen(java.util.function.LongToIntFunction after) { return s -> after.applyAsInt(applyAsLong(s)); } @Override public default IntToLongMorphism andThen(java.util.function.LongUnaryOperator after) { return s -> after.applyAsLong(applyAsLong(s)); } @Override public default IntToDoubleMorphism andThen(java.util.function.LongToDoubleFunction after) { return s -> after.applyAsDouble(applyAsLong(s)); } @Override public default <T> IntToObjMorphism<T> andThen(java.util.function.LongFunction<? extends T> after) { return s -> after.apply(applyAsLong(s)); } @Override public default IntToLongMorphism compose(java.util.function.IntUnaryOperator before) { return s -> applyAsLong(before.applyAsInt(s)); } @Override public default LongMorphism compose(java.util.function.LongToIntFunction before) { return s -> applyAsLong(before.applyAsInt(s)); } @Override public default DoubleToLongMorphism compose(java.util.function.DoubleToIntFunction before) { return s -> applyAsLong(before.applyAsInt(s)); } @Override public default <S> ObjToLongMorphism<S> compose(java.util.function.ToIntFunction<? super S> before) { return s -> applyAsLong(before.applyAsInt(s)); } } interface IntToDoubleMorphism extends IntToObjMorphism<Double>, ObjToDoubleMorphism<Integer>, java.util.function.IntToDoubleFunction { @Override public default Double apply(Integer operand) { return applyAsDouble((int) operand); } @Override public default Double apply(int operand) { return applyAsDouble(operand); } @Override public default double applyAsDouble(Integer operand) { return applyAsDouble((int) operand); } @Override public default IntMorphism andThen(java.util.function.DoubleToIntFunction after) { return s -> after.applyAsInt(applyAsDouble(s)); } @Override public default IntToLongMorphism andThen(java.util.function.DoubleToLongFunction after) { return s -> after.applyAsLong(applyAsDouble(s)); } @Override public default IntToDoubleMorphism andThen(java.util.function.DoubleUnaryOperator after) { return s -> after.applyAsDouble(applyAsDouble(s)); } @Override public default <T> IntToObjMorphism<T> andThen(java.util.function.DoubleFunction<? extends T> after) { return s -> after.apply(applyAsDouble(s)); } @Override public default IntToDoubleMorphism compose(java.util.function.IntUnaryOperator before) { return s -> applyAsDouble(before.applyAsInt(s)); } @Override public default LongToDoubleMorphism compose(java.util.function.LongToIntFunction before) { return s -> applyAsDouble(before.applyAsInt(s)); } @Override public default DoubleMorphism compose(java.util.function.DoubleToIntFunction before) { return s -> applyAsDouble(before.applyAsInt(s)); } @Override public default <S> ObjToDoubleMorphism<S> compose(java.util.function.ToIntFunction<? super S> before) { return s -> applyAsDouble(before.applyAsInt(s)); } } interface LongToIntMorphism extends LongToObjMorphism<Integer>, ObjToIntMorphism<Long>, java.util.function.LongToIntFunction { @Override public default Integer apply(Long operand) { return applyAsInt((long) operand); } @Override public default Integer apply(long operand) { return applyAsInt(operand); } @Override public default int applyAsInt(Long operand) { return applyAsInt((long) operand); } @Override public default LongToIntMorphism andThen(java.util.function.IntUnaryOperator after) { return s -> after.applyAsInt(applyAsInt(s)); } @Override public default LongMorphism andThen(java.util.function.IntToLongFunction after) { return s -> after.applyAsLong(applyAsInt(s)); } @Override public default LongToDoubleMorphism andThen(java.util.function.IntToDoubleFunction after) { return s -> after.applyAsDouble(applyAsInt(s)); } @Override public default <T> LongToObjMorphism<T> andThen(java.util.function.IntFunction<? extends T> after) { return s -> after.apply(applyAsInt(s)); } @Override public default IntMorphism compose(java.util.function.IntToLongFunction before) { return s -> applyAsInt(before.applyAsLong(s)); } @Override public default LongToIntMorphism compose(java.util.function.LongUnaryOperator before) { return s -> applyAsInt(before.applyAsLong(s)); } @Override public default DoubleToIntMorphism compose(java.util.function.DoubleToLongFunction before) { return s -> applyAsInt(before.applyAsLong(s)); } @Override public default <S> ObjToIntMorphism<S> compose(java.util.function.ToLongFunction<? super S> before) { return s -> applyAsInt(before.applyAsLong(s)); } } interface DoubleToIntMorphism extends DoubleToObjMorphism<Integer>, ObjToIntMorphism<Double>, java.util.function.DoubleToIntFunction { @Override public default Integer apply(Double operand) { return applyAsInt((double) operand); } @Override public default Integer apply(double operand) { return applyAsInt(operand); } @Override public default int applyAsInt(Double operand) { return applyAsInt((double) operand); } @Override public default DoubleToIntMorphism andThen(java.util.function.IntUnaryOperator after) { return s -> after.applyAsInt(applyAsInt(s)); } @Override public default DoubleToLongMorphism andThen(java.util.function.IntToLongFunction after) { return s -> after.applyAsLong(applyAsInt(s)); } @Override public default DoubleMorphism andThen(java.util.function.IntToDoubleFunction after) { return s -> after.applyAsDouble(applyAsInt(s)); } @Override public default <T> DoubleToObjMorphism<T> andThen(java.util.function.IntFunction<? extends T> after) { return s -> after.apply(applyAsInt(s)); } @Override public default IntMorphism compose(java.util.function.IntToDoubleFunction before) { return s -> applyAsInt(before.applyAsDouble(s)); } @Override public default LongToIntMorphism compose(java.util.function.LongToDoubleFunction before) { return s -> applyAsInt(before.applyAsDouble(s)); } @Override public default DoubleToIntMorphism compose(java.util.function.DoubleUnaryOperator before) { return s -> applyAsInt(before.applyAsDouble(s)); } @Override public default <S> ObjToIntMorphism<S> compose(java.util.function.ToDoubleFunction<? super S> before) { return s -> applyAsInt(before.applyAsDouble(s)); } } interface LongToObjMorphism<T> extends Morphism<Long, T>, java.util.function.LongFunction<T> { @Override public 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)); } @Override public 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 DoubleToObjMorphism<T> extends Morphism<Double, T>, java.util.function.DoubleFunction<T> { @Override public 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)); } @Override public 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 ObjToLongMorphism<S> extends Morphism<S, Long>, java.util.function.ToLongFunction<S> { @Override public 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)); } @Override public default <U> ObjToLongMorphism<U> compose(java.util.function.Function<? super U, ? extends S> before) { return s -> applyAsLong(before.apply(s)); } } interface ObjToDoubleMorphism<S> extends Morphism<S, Double>, java.util.function.ToDoubleFunction<S> { @Override public 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)); } @Override public default <U> ObjToDoubleMorphism<U> compose(java.util.function.Function<? super U, ? extends S> before) { return s -> applyAsDouble(before.apply(s)); } } interface LongMorphism extends LongToObjMorphism<Long>, ObjToLongMorphism<Long>, java.util.function.LongUnaryOperator { @Override public default Long apply(Long operand) { return applyAsLong((long) operand); } @Override public default Long apply(long operand) { return applyAsLong(operand); } @Override public default long applyAsLong(Long operand) { return applyAsLong((long) operand); } @Override public default LongToIntMorphism andThen(java.util.function.LongToIntFunction after) { return s -> after.applyAsInt(applyAsLong(s)); } @Override public 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)); } @Override public default LongToDoubleMorphism andThen(java.util.function.LongToDoubleFunction after) { return s -> after.applyAsDouble(applyAsLong(s)); } @Override public default <T> LongToObjMorphism<T> andThen(java.util.function.LongFunction<? extends T> after) { return s -> after.apply(applyAsLong(s)); } @Override public default IntToLongMorphism compose(java.util.function.IntToLongFunction before) { return s -> applyAsLong(before.applyAsLong(s)); } @Override public 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)); } @Override public default DoubleToLongMorphism compose(java.util.function.DoubleToLongFunction before) { return s -> applyAsLong(before.applyAsLong(s)); } @Override public 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 DoubleToLongMorphism extends DoubleToObjMorphism<Long>, ObjToLongMorphism<Double>, java.util.function.DoubleToLongFunction { @Override public default Long apply(Double operand) { return applyAsLong((double) operand); } @Override public default Long apply(double operand) { return applyAsLong(operand); } @Override public default long applyAsLong(Double operand) { return applyAsLong((double) operand); } @Override public default DoubleToIntMorphism andThen(java.util.function.LongToIntFunction after) { return s -> after.applyAsInt(applyAsLong(s)); } @Override public default DoubleToLongMorphism andThen(java.util.function.LongUnaryOperator after) { return s -> after.applyAsLong(applyAsLong(s)); } @Override public default DoubleMorphism andThen(java.util.function.LongToDoubleFunction after) { return s -> after.applyAsDouble(applyAsLong(s)); } @Override public default <T> DoubleToObjMorphism<T> andThen(java.util.function.LongFunction<? extends T> after) { return s -> after.apply(applyAsLong(s)); } @Override public default IntToLongMorphism compose(java.util.function.IntToDoubleFunction before) { return s -> applyAsLong(before.applyAsDouble(s)); } @Override public default LongMorphism compose(java.util.function.LongToDoubleFunction before) { return s -> applyAsLong(before.applyAsDouble(s)); } @Override public default DoubleToLongMorphism compose(java.util.function.DoubleUnaryOperator before) { return s -> applyAsLong(before.applyAsDouble(s)); } @Override public default <S> ObjToLongMorphism<S> compose(java.util.function.ToDoubleFunction<? super S> before) { return s -> applyAsLong(before.applyAsDouble(s)); } } interface LongToDoubleMorphism extends LongToObjMorphism<Double>, ObjToDoubleMorphism<Long>, java.util.function.LongToDoubleFunction { @Override public default Double apply(Long operand) { return applyAsDouble((long) operand); } @Override public default Double apply(long operand) { return applyAsDouble(operand); } @Override public default double applyAsDouble(Long operand) { return applyAsDouble((long) operand); } @Override public default LongToIntMorphism andThen(java.util.function.DoubleToIntFunction after) { return s -> after.applyAsInt(applyAsDouble(s)); } @Override public default LongMorphism andThen(java.util.function.DoubleToLongFunction after) { return s -> after.applyAsLong(applyAsDouble(s)); } @Override public default LongToDoubleMorphism andThen(java.util.function.DoubleUnaryOperator after) { return s -> after.applyAsDouble(applyAsDouble(s)); } @Override public default <T> LongToObjMorphism<T> andThen(java.util.function.DoubleFunction<? extends T> after) { return s -> after.apply(applyAsDouble(s)); } @Override public default IntToDoubleMorphism compose(java.util.function.IntToLongFunction before) { return s -> applyAsDouble(before.applyAsLong(s)); } @Override public default LongToDoubleMorphism compose(java.util.function.LongUnaryOperator before) { return s -> applyAsDouble(before.applyAsLong(s)); } @Override public default DoubleMorphism compose(java.util.function.DoubleToLongFunction before) { return s -> applyAsDouble(before.applyAsLong(s)); } @Override public default <S> ObjToDoubleMorphism<S> compose(java.util.function.ToLongFunction<? super S> before) { return s -> applyAsDouble(before.applyAsLong(s)); } } interface DoubleMorphism extends DoubleToObjMorphism<Double>, ObjToDoubleMorphism<Double>, java.util.function.DoubleUnaryOperator { @Override public default Double apply(Double operand) { return applyAsDouble((double) operand); } @Override public default Double apply(double operand) { return applyAsDouble(operand); } @Override public default double applyAsDouble(Double operand) { return applyAsDouble((double) operand); } @Override public default DoubleToIntMorphism andThen(java.util.function.DoubleToIntFunction after) { return s -> after.applyAsInt(applyAsDouble(s)); } @Override public default DoubleToLongMorphism andThen(java.util.function.DoubleToLongFunction after) { return s -> after.applyAsLong(applyAsDouble(s)); } @Override public 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)); } @Override public default IntToDoubleMorphism compose(java.util.function.IntToDoubleFunction before) { return s -> applyAsDouble(before.applyAsDouble(s)); } @Override public default LongToDoubleMorphism compose(java.util.function.LongToDoubleFunction before) { return s -> applyAsDouble(before.applyAsDouble(s)); } @Override public 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); } }