QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#296067#1418. Mountain Rescue Team170 1ms3632kbC++203.6kb2024-01-02 06:59:212024-01-02 06:59:22

Judging History

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

  • [2024-01-02 06:59:22]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3632kb
  • [2024-01-02 06:59:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#include "grader.h"
bool g = false;
template<class F>
vector<int> smawk(int h, int w, F f){
  auto dfs = [&](auto self, vector<int> &row, vector<int> &col) -> vector<int>{
    int n = row.size();
    if(n == 0) return {};
    vector<int> ncol;
    ncol.reserve(n);
    for(int i:col){
      while(!ncol.empty() && f(row[ncol.size()-1], ncol.back()) > f(row[ncol.size()-1], i)) ncol.pop_back();
      if(ncol.size() < n) ncol.push_back(i);
    }
    vector<int> row_odd;
    row_odd.reserve(n/2+1);
    for(int i = 1; i < n; i+=2) row_odd.push_back(row[i]);
    vector<int> ans = self(self, row_odd, ncol);
    vector<int> res(n);
    for(int i = 0; i < row_odd.size(); i++) res[i*2+1] = ans[i];
    int j = 0;
    for(int i = 0; i < n; i+=2){
      int last = (i == n-1 ? ncol.back() : res[i+1]);
      res[i] = ncol[j];
      while(ncol[j] < last){
        ++j;
        if(f(row[i], res[i]) > f(row[i], ncol[j])) res[i] = ncol[j];
      }
    }
    return res;
  };
  vector<int> row(h), col(w);
  iota(row.begin(), row.end(), 0);
  iota(col.begin(), col.end(), 0);
  return dfs(dfs, row, col);
}
void Rescue(int R, int C, int RS, int CS, int X){
  map<pair<int, int>, int> m;
  int l1 = 1, r1 = RS+1;
  while(r1-l1 > 1){
    int mid = (l1+r1)/2;
    int x = mid, y = CS;
    int h = m.count({x, y}) ? m[{x, y}] : Measure(x, y);
    if(!m.count({x, y})){
      if(h == X){
        Pinpoint(x, y);
        g = true;
      }
      m[{x, y}] = h;
    }
    if(h < X) l1 = mid;
    else r1 = mid;
  }
  int l2 = RS, r2 = R+1;
  while(r2-l2 > 1){
    int mid = (l2+r2)/2;
    int x = mid, y = CS;
    int h = m.count({x, y}) ? m[{x, y}] : Measure(x, y);
    if(!m.count({x, y})){
      if(h == X){
        Pinpoint(x, y);
        g = true;
      }
      m[{x, y}] = h;
    }
    if(h < X) r2 = mid;
    else l2 = mid;
  }
  auto f1 = [&](int x, int y){
    if(g) return 0;
    x = r1+x;
    y = CS-y;
    int h = m.count({x, y}) ? m[{x, y}] : Measure(x, y);
    if(!m.count({x, y})){
      if(h == X){
        Pinpoint(x, y);
        g = true;
      }
      m[{x, y}] = h;
    }
    return abs(h-X);
  };
  auto s1 = smawk(RS-r1+1, CS, f1);
  for(int i = 0; i < s1.size(); i++){
    cerr << s1[i] << " ";
    f1(i, s1[i]);
  }
  cerr << endl;
  auto f2 = [&](int x, int y){
    if(g) return 0;
    x = r1+x;
    y = CS+y;
    int h = m.count({x, y}) ? m[{x, y}] : Measure(x, y);
    if(!m.count({x, y})){
      if(h == X){
        Pinpoint(x, y);
        g = true;
      }
      m[{x, y}] = h;
    }
    return abs(h-X);
  };
  auto s2 = smawk(RS-r1+1, C-CS+1, f2);
  for(int i = 0; i < s2.size(); i++){
    cerr << s2[i] << " ";
    f2(i, s2[i]);
  }
  cerr << endl;
  auto f3 = [&](int x, int y){
    if(g) return 0;
    x = l2-x;
    y = CS-y;
    int h = m.count({x, y}) ? m[{x, y}] : Measure(x, y);
    if(!m.count({x, y})){
      if(h == X){
        Pinpoint(x, y);
        g = true;
      }
      m[{x, y}] = h;
    }
    return abs(h-X);
  };
  auto s3 = smawk(l2-RS+1, CS, f3);
  for(int i = 0; i < s3.size(); i++){
    cerr << s3[i] << " ";
    f3(i, s3[i]);
  }
  cerr << endl;
  auto f4 = [&](int x, int y){
    if(g) return 0;
    x = l2-x;
    y = CS+y;
    int h = m.count({x, y}) ? m[{x, y}] : Measure(x, y);
    if(!m.count({x, y})){
      if(h == X){
        Pinpoint(x, y);
        g = true;
      }
      m[{x, y}] = h;
    }
    return abs(h-X);
  };
  auto s4 = smawk(l2-RS+1, C-CS+1, f4);
  for(int i = 0; i < s4.size(); i++){
    cerr << s4[i] << " ";
    f4(i, s4[i]);
  }
  cerr << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 20
Accepted
time: 1ms
memory: 3632kb

input:

1 1 1 1 1
1

output:

Accepted

Test #2:

score: -20
Runtime Error

input:

2 2 2 2 1
1 2
3 4

output:

Unauthorized output

Subtask #2:

score: 0
Skipped

Dependency #1:

0%