QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#287652#5669. Traveling in Jade CityThMinh__Compile Error//C++143.3kb2023-12-20 21:11:592023-12-20 21:12:00

Judging History

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

  • [2023-12-20 21:12:00]
  • 评测
  • [2023-12-20 21:11:59]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
int n, k, m, q;
bool fix[N << 1];
int s[N << 1], g[N << 1], tr[N << 1];

struct rail {
   int u, v, t;
} c[N << 1];

struct query {
   char ch;
   int i, u, v;
} Q[N];

void init() {
   cin>>n>>k>>m>>q;
   for(int i = 1; i <= n; ++i) {
      int t; cin>>t;
      c[i] = {i, i % n + 1, t};
   }

   for(int i = 0; i <= m; ++i) {
      int t; cin>>t;
      if(!i) c[n + i + 1] = {1, n + 1, t};
      else if(i == m) c[n + i + 1] = {n + m, k, t};
      else c[n + i + 1] = {n + i, n + i + 1, t};
   }

   for(int i = 1; i <= q; ++i) {
      cin>>Q[i].ch;
      if(Q[i].ch == 'q') cin>>Q[i].u>>Q[i].v;
      else cin>>Q[i].i;
   }
}

void up(int x, int val) {
   while(x <= n + m + 1) {
      tr[x] += val;
      x += x & -x;
   }
}

int get(int x) {
   int res = 0;
   while(x) {
      res += tr[x];
      x -= x & -x;
   }
   return res;
}

int dis(int f, int l) {
   if(f > l) swap(f, l);
   bool ok = 1;
   if(f > n) ok = 0;

   int sum = 1e18, cnt = get(l - 1) - get(f - 1);
   if(ok) {
      int val1 = cnt ? 1e18 : s[l - 1] - s[f - 1];
      sum = min(sum, val1);

      int val2 = (get(n) - cnt) ? 1e18 : s[n] - (s[l - 1] - s[f - 1]);
      sum = min(sum, val2);
   }
   else if(!cnt) sum = min(sum, g[l - 1] - g[f - 1]);

   return sum;
}

void solve() {
   for(int i = 1; i <= n + m + 1; ++i) {
      if(i <= n) s[i] = s[i - 1] + c[i].t;
      if(i > n) g[i] = g[i - 1] + c[i].t;
   }

   for(int i = 1; i <= q; ++i) {
      char ch = Q[i].ch;
      if(ch == 'c') {
         int j = Q[i].i;
         int val = fix[j] ? -1 : 1;

         up(j, val);
         fix[j] ^= 1;
      }
      else if(ch == 'x') {
         int j = Q[i].i;
         int val = fix[n + j + 1] ? -1 : 1;

         up(n + j + 1, val);
         fix[n + j + 1] ^= 1;
      }
      else {
         int u = Q[i].u;
         int v = Q[i].v;
         if(u > v) swap(u, v);
         if(u == v) {
            cout<<0<<"\n";
            continue;
         }

         int ans = 1e18;

         if(u <= n && v <= n) {
            ans = min(ans, dis(u, v));

            if(get(n + m + 1) - get(n) == 0) {
               ans = min(ans, g[n + m + 1] + dis(1, u) + dis(k, v));
               ans = min(ans, g[n + m + 1] + dis(k, u) + dis(1, v));
            }
         }
         else if(u <= n && v > n) {
            ans = min(ans, dis(v + 1, n + 1) + dis(1, u));
            ans = min(ans, dis(v + 1, n + m + 2) + dis(k, u));
         }
         else {
            ans = min(ans, dis(u + 1, v + 1));

            int res = 1e18;
            res = min(res, dis(n + 1, u + 1) + dis(v + 1, n + m + 2));
            res = min(res, dis(n + m + 2, u + 1) + dis(v + 1, n + 1));

            ans = min(ans, res + dis(1, k));
         }

         if(ans >= 1e18) cout<<"impossible\n";
         else cout<<ans<<"\n";
      }
   }
}

int main () {
   cin.tie(0)->sync_with_stdio(0);
   if(fopen("Task.inp", "r")) {
      freopen("Task.inp", "r", stdin);
      freopen("WA.out", "w", stdout);
   }
   if(fopen("Train.inp", "r")) {
      freopen("Train.inp", "r", stdin);
      freopen("Train.out", "w", stdout);
   }

   init();

   return solve(), 0;
}

详细

cc1plus: error: ‘::main’ must return ‘int’
answer.code: In function ‘int main()’:
answer.code:137:14: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  137 |       freopen("Task.inp", "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
answer.code:138:14: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  138 |       freopen("WA.out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
answer.code:141:14: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  141 |       freopen("Train.inp", "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:142:14: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  142 |       freopen("Train.out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~