The question was not very clear at the beginning, and later I found thatEach feature appears the same number of times.
In this way, it becomes a simple hash problem. If we look at each feature as a (n + 1) hexadecimal number, we can evaluate the prefix and, if each feature of the I-j segment appears the same number of times, the minimum values of the I-1 vertex and the J vertex are equal, so it is good to judge by hash.
# Include <cstdio> # include <cstring> # include <iostream> # include <map> # include <set> # include <vector> # include <string> # include <queue> # include <deque> # include <bitset> # include <list> # include <cstdlib> # include <climits> # include <cmath> # include <ctime> # include <algorithm> # include <stack> # include <sstream> # include <numeric> # include <fstream> # include <functional> using namespace STD; # define MP make_pair # d Efine Pb push_backtypedef long ll; typedef unsigned long ull; typedef vector <int> VI; typedef pair <int, int> PII; const int INF = int_max/3; const double EPS = 1e-8; const ll linf = 1e17; const double dinf = 1e60; const int maxn = 100000 + 10; const int maxk = 30; const int mod = 65536; int N, K; struct node {int data [maxk]; node (INT val = 0) {int Pos = 0; memset (data, 0, sizeof (data )); while (VAL ){ Data [POS ++] = Val & 1; Val >>=1 ;}} bool operator ==( const node & node) const {for (INT I = 0; I <K; I ++) if (node. data [I]! = Data [I]) return false; return true ;}; node operator + (node A, Node B) {for (INT I = 0; I <K; I ++) {. data [I] + = B. data [I];} return a;} void con (node & node) {int minval = inf; For (INT I = 0; I <K; I ++) minval = min (minval, node. data [I]); For (INT I = 0; I <K; I ++) node. data [I]-= minval;} int gethash (const node & node) {int ret = 0; For (INT I = 0; I <K; I ++) {ret = RET * (n + 1) + node. data [I];} RET Urn RET & (mod-1);} node cow [maxn], Val [maxn]; int head [mod], NXT [maxn], POS [maxn], SZ; int ask (const node & node, int p) {int Hc = gethash (node); For (INT I = head [HC]; ~ I; I = NXT [I]) {If (Val [I] = node) return POS [I];} Val [SZ] = node; pos [SZ] = P; NXT [SZ] = head [HC]; head [HC] = SZ ++; return P;} int main () {While (scanf ("% d", & N, & K )! = EOF) {memset (Head,-1, sizeof (head); SZ = 0; For (INT I = 1; I <= N; I ++) {int TMP; scanf ("% d", & TMP); cow [I] = cow [I-1] + node (TMP) ;}for (INT I = 1; I <= N; I ++) con (COW [I]); int ans = 0; For (INT I = 0; I <= N; I ++) {// For (Int J = 0; j <K; j ++) printf ("% d", cow [I]. data [J]); putchar ('\ n'); int Pos = Ask (COW [I], I); ans = max (ANS, I-Pos );} printf ("% d \ n", ANS);} return 0 ;}
Poj 3474 gold balanced lineup hash