QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#119559#6669. Mapahos_lyric#0 1ms4140kbC++144.8kb2023-07-05 12:32:322024-07-04 00:17:52

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:17:52]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:4140kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-05 12:32:32]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


constexpr int MO = 131041;
int myhash(int x) {
  x = (20230705LL * x) % 1'000'000'403;
  return x % MO;
}

constexpr int E = 30;
constexpr int F = 17;
constexpr int G = 4;
constexpr int M0 = 150;

string toBinary(int len, int x) {
  string s(len, '?');
  for (int e = 0; e < len; ++e) s[e] = "01"[x >> e & 1];
  return s;
}
int fromBinary(const string &s) {
  const int len = s.size();
  int x = 0;
  for (int e = 0; e < len; ++e) x |= (s[e] - '0') << e;
  return x;
}

string encode(int N, const vector<int> &X, const vector<int> &Y) {
  vector<int> H(N);
  for (int i = 0; i < N; ++i) {
    H[i] = myhash(X[i]);
  }
  
  int minCost = 1001001001;
  int am = -1;
  for (int a = 0; a < 1 << G; ++a) {
    const int M = M0 + a;
    vector<int> freq(M);
    for (int i = 0; i < N; ++i) {
      ++freq[H[i] % M];
    }
    int cost = M;
    for (int m = 0; m < M; ++m) {
      cost += F * max(freq[m] - 1, 0);
    }
cerr<<"M = "<<M<<": cost = "<<cost<<endl;
    if (chmin(minCost, cost)) {
      am = a;
    }
  }
  const int M = M0 + am;
  
  vector<vector<pair<int, int>>> hiss(M);
  for (int i = 0; i < N; ++i) {
    hiss[H[i] % M].emplace_back(H[i], i);
  }
  for (int m = 0; m < M; ++m) {
    auto &his = hiss[m];
    sort(his.begin(), his.end());
  }
// cerr<<"hiss = "<<hiss<<endl;
  string S;
  S += toBinary(G, am);
  for (int m = 0; m < M; ++m) {
    const auto &his = hiss[m];
    for (const auto &hi : his) {
      const int i = hi.second;
      S += toBinary(E, Y[i]);
    }
  }
  for (int m = 0; m < M; ++m) {
    const auto &his = hiss[m];
    S += (!his.empty()) ? '1' : '0';
  }
  for (int m = 0; m < M; ++m) {
    const auto &his = hiss[m];
    for (int j = 1; j < (int)his.size(); ++j) {
      S += toBinary(F, his[j].first);
    }
  }
  return S;
}

vector<int> decode(int N, int Q, int K, const string &S, const vector<int> &Z) {
  int M;
  map<int, int> mapa, nazo;
  {
    int cur = 0;
    const int am = fromBinary(S.substr(cur, G)); cur += G;
    M = M0 + am;
    vector<int> Y(N);
    for (int i = 0; i < N; ++i) {
      Y[i] = fromBinary(S.substr(cur, E)); cur += E;
    }
    vector<vector<int>> hss(M);
    for (int m = 0; m < M; ++m) {
      const char any = S[cur++];
      if (any != '0') {
        hss[m].push_back(-1);
      }
    }
    for (; cur < K; ) {
      const int h = fromBinary(S.substr(cur, F)); cur += F;
      hss[h % M].push_back(h);
    }
// cerr<<"hss = "<<hss<<endl;
    {
      int i = 0;
      for (int m = 0; m < M; ++m) {
        for (const int h : hss[m]) {
          const int y = Y[i++];
          if (~h) {
            mapa[h] = y;
          } else {
            nazo[m] = y;
          }
        }
      }
    }
    assert(cur == K);
  }
  vector<int> ans(Q);
  for (int q = 0; q < Q; ++q) {
    const int h = myhash(Z[q]);
    auto it = mapa.find(h);
    if (it != mapa.end()) {
      ans[q] = it->second;
    } else {
      ans[q] = nazo[h % M];
    }
  }
  return ans;
}

int main() {
  int T;
  scanf("%d", &T);
  if (T == 1) {
    int N;
    scanf("%d", &N);
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d%d", &X[i], &Y[i]);
    }
    const string S = encode(N, X, Y);
    const int K = S.size();
    printf("%d\n", K);
    puts(S.c_str());
  } else {
    int N, Q, K;
    scanf("%d%d%d", &N, &Q, &K);
    char buf[6010];
    scanf("%s", buf);
    const string S = buf;
    vector<int> Z(Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d", &Z[q]);
    }
    const auto ans = decode(N, Q, K, S, Z);
    for (int q = 0; q < Q; ++q) {
      printf("%d\n", ans[q]);
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 82.8667
Acceptable Answer
time: 1ms = 1ms + 0ms
memory: 3868kb,3888kb

input:

1
100
495528311 963488152
269613430 443544124
700489871 792354118
151890319 506569919
180452297 13229948
684464994 543841485
978085128 903812192
238355172 441140842
28061035 783291471
530823766 718942732
936853023 439421263
201361623 226633955
304644844 778868118
864860135 461524170
88300500 6959354...

output:

3514
1100000111101000011101111110010010000110011001010110110110100111001101010011000100101110100111000110001010101100010001010011100100101111001000101011011101010101100110001011010010010110001100000100110001011011010101110000001010000101011011000001000100110001101101111010010101000100110110111001111...

input:

2
100 79 3514
1100000111101000011101111110010010000110011001010110110110100111001101010011000100101110100111000110001010101100010001010011100100101111001000101011011101010101100110001011010010010110001100000100110001011011010101110000001010000101011011000001000100110001101101111010010101000100110110...

output:

310305144
821194635
174780370
903812192
805026231
996046536
439421263
645287342
90686849
20101025
440972097
543841485
176553522
249563964
461524170
348624865
848301562
506569919
306718453
206848250
382805509
278712030
964702808
868944393
493895143
39665197
574757075
441140842
785665865
229376884
551...

result:

points 0.82866666670 ok K = 3514

Test #2:

score: 83.3333
Acceptable Answer
time: 1ms = 1ms + 0ms
memory: 3876kb,3856kb

input:

1
100
743248071 842720888
367650901 130970775
297946283 705168964
771526942 537186020
245003150 707948455
643491261 668001146
311535032 293708068
183828318 18515526
593973840 915870006
102456762 64193833
729806890 839221652
47145974 35682954
668676377 228428310
370700393 569441954
250911162 48980047...

output:

3500
0110110111110101101010111000000011001000110000010000111100000100101110001100001110001100101110000100010001010000111101001001110110111111101001001010110101100110111100100001011010001001110010001111010010000100111101011010000101000110111001101100100010111110010001010101000111100101110011010110111...

input:

2
100 79 3500
0110110111110101101010111000000011001000110000010000111100000100101110001100001110001100101110000100010001010000111101001001110110111111101001001010110101100110111100100001011010001001110010001111010010000100111101011010000101000110111001101100100010111110010001010101000111100101110011...

output:

442563406
97578442
469403815
293708068
138158276
720700065
839221652
674386240
810209830
563527225
259979005
668001146
813899310
943777483
569441954
226088806
825435650
537186020
131383422
83733737
830289758
425793016
858146541
609883097
414389335
407054915
47572024
18515526
276587480
810627636
4972...

result:

points 0.83333333330 ok K = 3500

Test #3:

score: 84.6333
Acceptable Answer
time: 0ms = 0ms + 0ms
memory: 3872kb,3936kb

input:

1
100
770174568 168127255
893508708 185778664
976425263 477317099
287595878 512153851
621600374 418802856
818787535 612197605
796811122 566496677
789841517 873731343
43178468 619503942
597852289 471053284
66112404 635260765
158101403 199253397
680158192 123081916
626776438 29107026
721141470 5177084...

output:

3461
1000011100000100010000010101010001011111110011011111010100100000010001001011101010100001111000110110011010000000000100101100101101111011101100000100101010011010111011011001011101111010000101010011011001101111000110111101111110010110011101101010010100011000011000001101011101011011011111101010110...

input:

2
100 79 3461
1000011100000100010000010101010001011111110011011111010100100000010001001011101010100001111000110110011010000000000100101100101101111011101100000100101010011010111011011001011101111010000101010011011001101111000110111101111110010110011101101010010100011000011000001101011101011011011111...

output:

676203467
418593456
222540092
566496677
487711174
155177230
635260765
19655934
405420089
197948311
16997620
612197605
623431791
654167214
29107026
103769907
951695033
512153851
401411177
839097490
141196222
886472586
767476542
270436089
885084406
492744649
861074271
873731343
744691837
300804222
364...

result:

points 0.84633333330 ok K = 3461

Test #4:

score: 82.8
Acceptable Answer
time: 0ms = 0ms + 0ms
memory: 3928kb,4120kb

input:

1
100
546594289 9670068
665528790 773039281
266567267 744830423
338924380 918542055
413001686 717894752
786408307 211692098
280986141 432842000
195582858 921321743
412109607 485887870
262421557 244551274
303481411 585109375
922835159 77375674
276669713 485047938
748493209 63888398
37129726 285918022...

output:

3516
1010110001101100111010111110100011000011000101101110011011000110110100101110000111010100010110101000100111001110101001010000011101101111110010001111100100011000101001100111100001101110001100110111101111111000111110001101100111011110101001110101100111000101011011001001001101110011010011101010100...

input:

2
100 79 3516
1010110001101100111010111110100011000011000101101110011011000110110100101110000111010100010110101000100111001110101001010000011101101111110010001111100100011000101001100111100001101110001100110111101111111000111110001101100111011110101001110101100111000101011011001001001101110011010011...

output:

43372101
204611063
352593757
432842000
142147490
891337416
585109375
743309504
647533065
464964608
876089821
211692098
955710889
971589766
63888398
781195091
748872098
918542055
738134414
271774069
559783342
631668225
32245370
502187994
978371138
563783889
900635155
921321743
760555399
270665755
276...

result:

points 0.8280 ok K = 3516

Test #5:

score: 0
Wrong Answer
time: 0ms = 0ms + 0ms
memory: 3868kb,4140kb

input:

1
100
326454605 159474960
11647328 932941462
367166680 626258331
846588658 385992166
148602944 380296908
32123445 521548223
146657758 872883623
78417135 361494853
902204073 975297913
50096537 520296997
687284103 420187394
93781442 87808395
503014564 573344902
720903126 546124141
87676450 646360824
9...

output:

3524
1011000010011100101000101111111100011000010011000100110100010001110110010111001101010000100001100011011100010001110011001010101000101001111111010001101010101001000101100011000000111110011010010111000111011001111011101100101101000001111001010110001101010011011110101100100101101100110000110101110...

input:

2
100 79 3524
1011000010011100101000101111111100011000010011000100110100010001110110010111001101010000100001100011011100010001110011001010101000101001111111010001101010101001000101100011000000111110011010010111000111011001111011101100101101000001111001010110001101010011011110101100100101101100110000...

output:

744601533
267129639
871217352
872883623
255371549
162360942
420187394
62984915
242781986
691399852
480380990
521548223
281944751
214089065
546124141
380557861
669664079
385992166
150840342
413877880
634078816
965530575
770169571
451364705
804171981
524846617
166621075
361494853
603970305
891038427
6...

result:

wrong answer wrong answer on query #13: read 281944751 but expected 206206675