arjunarul

Custom Judge - Interactive Problem

Mar 8th, 2019
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include "spoj_interactive.h"
  2. #include <bits/stdc++.h>
  3. #define MAX 500005
  4. long long int a[MAX],n,cnt[MAX];
  5. using namespace std;
  6. void verdict_wrong(int i)
  7. {
  8.     fprintf(spoj_for_tested,"%d\n",i);
  9.     spoj_assert(false);
  10. }
  11. void finalizeIT(int score)
  12. {
  13.     fprintf(spoj_score, "%d", score);
  14. }
  15. int main()
  16. {
  17.     spoj_init();
  18.     int t;
  19.     fscanf(spoj_p_in,"%d", &t);
  20.     fprintf(spoj_for_tested,"%d\n",t);
  21.     while(t--)
  22.     {
  23.         fscanf(spoj_p_in,"%lld",&n);
  24.         fprintf(spoj_for_tested,"%lld\n",n);
  25.         long long int querylimit= n;
  26.         long long int i,j;
  27.         memset(a,0,sizeof(a));
  28.         memset(cnt,0,sizeof(cnt));
  29.         for(i=1;i<=n;i++)
  30.         {
  31.             fscanf(spoj_p_in,"%lld",&a[i]);
  32.         }
  33.         j=0;
  34.         bool ac=false;
  35.         int ch;
  36.         while(true)
  37.         {
  38.             j++;
  39.             fscanf(spoj_t_out,"%d",&ch);
  40.             if(ch!=1)
  41.             {
  42.                 break;
  43.             }
  44.             if(j<=querylimit)
  45.             {
  46.                 long long int x,y,z;
  47.                 fscanf(spoj_t_out,"%lld",&x);
  48.                 fscanf(spoj_t_out,"%lld",&y);
  49.                 fscanf(spoj_t_out,"%lld",&z);
  50.                 cnt[x]++;cnt[y]++;cnt[z]++;
  51.                 if(x<=n && y<=n && z<=n && x>=1 && y>=1 && z>=1 && cnt[x]<=3 && cnt[y]<=3 && cnt[z]<=3)
  52.                 {
  53.                     fprintf(spoj_for_tested,"%lld\n",(a[x]^a[y]^a[z]));
  54.                 }
  55.                 else
  56.                 {
  57.                     verdict_wrong(-1);
  58.                 }
  59.             }
  60.             else
  61.             {
  62.                 break;
  63.             }
  64.         }
  65.         if(ch==2)
  66.         {
  67.             long long int x,fl=1;
  68.             for(i=1;i<=n;i++)
  69.             {
  70.                 fscanf(spoj_t_out,"%lld",&x);
  71.                 if(x!=a[i])
  72.                 fl=0;
  73.             }
  74.             if(fl)
  75.             {
  76.                 fprintf(spoj_for_tested,"%d\n",1);
  77.                 ac=true;
  78.             }
  79.         }
  80.         if(!ac)
  81.         {
  82.             verdict_wrong(-1);
  83.         }
  84.     }
  85.     finalizeIT(1);
  86.     return 0;
  87. }
Add Comment
Please, Sign In to add comment