This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;
int main()
{
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> P(N), Q(M), cnt(K);
  for (int i=0; i<N; i++) cin >> P[i];
  for (int i=0; i<M; i++) cin >> Q[i];
  for (int i=0; i<K; i++) cin >> cnt[i];
  vector<int> S(1000001);
  for (int i=0; i<N; i++)
    for (int j=P[i]; j<=1000000; j+=P[i])
      S[j] --;
  for (int i=0; i<M; i++)
    for (int j=Q[i]; j<=1000000; j+=Q[i])
      if (S[j] >= 0) S[j] ++;
  int cc = 0;
  for (int i=1; i<=1000000; i++)
    if (S[i] > 0) {
      cc ++;
      S[i] = cc;
    } else S[i] = 0;
  int xx = 0;
  for (int i=0; i<K; i++) xx ^= S[cnt[i]];
  for (int i=0; i<K; i++) {
    int target = S[cnt[i]] ^ xx;
    if (S[cnt[i]] > 0 && target < S[cnt[i]]) {
      int dd = 0, res = 0;
      for (int j=0; j<cnt[i]; j++) {
        if (S[j] == target) {
          res = cnt[i] - j;
          dd ++;
        }
      }
      cout << dd << " " << res << endl;
    } else cout << "0 0" << endl;
  }
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |