Please help me reduce the code execution time

Can any one help please help reduce the running time of this code?
1≤T≤300
1≤N, M, Q≤105
1≤Xi≤N for each valid i
1≤Yi≤M for each valid i
the sum of N on all test cases does not exceed 3.105
the sum of M on all test cases does not exceed 3.105
the sum of Q on all test cases does not exceed 3.105

#include 
using namespace std;

int main() {
int t;
cin>>t;
int n,m,q;
int x,y;
int count,i,l,j;
for(int o=0;o

bitcoin core – Clarification on the execution of a complex script with OP_CHECKLOCKTIMEVERIFY

I quote this example of BIP65

BIP 65 has this bitcoin script code

 IF
     CHECKLOCKTIMEVERIFY DROP
     CHECKSIGVERIFY
    1
 ELSE
    2
 ENDIF
   2 CHECKMULTISIG

And with this bitcoin scriptSig is possible unlock the transaction

  • Now with this ScriptSig 0 0
  • after 3 months with this ScirpSig 0 1

But I do not understand this part of If-then-else

ELSE
    2

When is it executed and what I do not understand inside the if-then-else condition?

python 3.x – How to optimize the execution of a script?

Hello, hello, I hope you are well. The next is to ask if you know of a way to improve this script with regard to processing time. Since it takes me up to half an hour to process the information, I discovered that whoever is renting me the process is the function all () and so I wanted to ask if there is another way to improve this script performance. These all () conditions allow me to filter a series of lists containing special conditions (if they are all negative or positive, or if it has changed sign) I greatly appreciate your collaboration.

for j in range(0,len(zmeshmesh)):
    Bmeshaux=()
    Bmeshauxred=()
    Bmeshauxholg=()
    for r in range(len(zmeshmesh(j))):
        zmeshiter=()
        zmeshiterred=()
        zmeshiterholg=()
        for m in range(len(zd(j))):
            zmeshiter.append(zmeshmesh(j)(r)-zd(j)(m)) #normalizando vector de cada estación con los 3 mètodos
            zmeshiterred.append(zmeshmeshred(j)(r)-zd(j)(m))
            zmeshiterholg.append(zmeshmeshholg(j)(r)-zd(j)(m))
            for i in range(0,len(zmeshiter),1): #ciclo para identificar cambio de signo en normalizada
                if (all(x > 0 for x in zmeshiter)) or (all(x < 0 for x in zmeshiter)):
                    yi,yf=0,0
                if (zmeshiter(i)>=0 and zmeshiter(i-1)<0):
                    start=i
                    try:
                        yi=round((zmeshmesh(j)(r)-zd(j)(start))*((yd(j)(start-1)-yd(j)(start))/(zd(j)(start-1)-zd(j)(start)))+yd(j)(start),2)
                    except:
                        yi=round((zmeshmesh(j)(r)-zd(j)(start))*((yd(j)(start-2)-yd(j)(start))/(zd(j)(start-2)-zd(j)(start)))+yd(j)(start),2)
                    if (all(s>0 for s in zmeshiter(start::))):
                        yi=0
                if (zmeshiter(i)<=0 and zmeshiter(i-1)>0):
                    end=i
                    try:
                        yf=round((zmeshmesh(j)(r)-zd(j)(end))*((yd(j)(end-1)-yd(j)(end))/(zd(j)(end-1)-zd(j)(end)))+yd(j)(end),2)
                    except:
                        yf=round((zmeshmesh(j)(r)-zd(j)(end))*((yd(j)(end-2)-yd(j)(end))/(zd(j)(end-2)-zd(j)(end)))+yd(j)(end),2)
                    if all((s>0 for s in zmeshiter(0:end))):
                        yf=0

mysql – Are there tools that support the submission, review, approval, and execution workflows for database queries?

We are a very small configuration in the e-commerce space. More than often, it is necessary to manually correct the data in our MySQL database via SQL query execution. There is 1 database administrator in our configuration. He is currently overwhelmed by the manual execution of queries and must be available every day for part of the day to run queries.

I am looking for a database query administration tool that can:

  1. Allows an end user (sender) to generate a database query request
  2. Allows a DBA (reviewer) to review the database query and approve / reject a query
  3. Executes the approved query on the selected database and returns the results by email to the sender and reviewer.

A very simple tool can be built in house but the bandwidth of the engineering teams is not available.

c – This program reads from the serial port, saves this in a text file, increments the file name at each execution

I want to condense it and get rid of any programming error noob.

The code works well but I know it is not as elegant as it could be and I really want to improve it. Your advice would be great!

I spoke to other engineers and got some basic help, but not much.

int main(){
//OPENING SERIAL PORT

int res = 0;        //variables to be passed to functinos
int logNum = 0;
HANDLE hComm;
hComm = CreateFile( "\\.\COM4",                //port name
                    GENERIC_READ | GENERIC_WRITE, //Read/Write
                    0,                            // No Sharing
                    NULL,                         // No Security
                    OPEN_EXISTING,// Open existing port only
                    0,            // Non Overlapped I/O
                    NULL);        // Null for Comm Devices

  if (hComm == INVALID_HANDLE_VALUE){ //print if COM port wont open
      printf("Error opening port");
      exit(42);
  }
  else {
      printf("Opening of port successfuln");   //Print to know serial port is open
  }

//Calling necessary functions
serialPort(hComm);
res = fileExist();
logNum = readPort(hComm, res);
parseFile(logNum);
CloseHandle(hComm);//Closing the Serial Port
return 0;   //main returns 0
}



void serialPort(HANDLE Comms){
//CONFIGURING SERIAL PORT
    BOOL Status;
    DCB dcbSerialParams = { 0 }; // Initializing DCB structure
    dcbSerialParams.DCBlength = sizeof(dcbSerialParams);

    dcbSerialParams.BaudRate = CBR_57600;  // Setting BaudRate = 9600
    dcbSerialParams.ByteSize = 8;         // Setting ByteSize = 8
    dcbSerialParams.StopBits = ONESTOPBIT;// Setting StopBits = 1
    dcbSerialParams.Parity   = NOPARITY;  // Setting Parity = None

    SetCommState(Comms, &dcbSerialParams); //Assignin serial settings to comm handle
    Status = EscapeCommFunction(Comms, SETRTS); //RTS Request to Send Signal to esentially reset Serial port (arduino)
    Status = EscapeCommFunction(Comms, SETDTR); //DTR data terminal ready, PC side terminal ready to recieve data

}


int fileExist(void){
//DOES FILENAME ALREADY EXIST

int result = 0;
char testNum(10);    
char fp(80);
char file(80) = "C:/Users/jgrayjt/Documents/Logs/TestLog_";
char fileEnd(5) = ".txt";

for (int i = 1; i < 1000; i++){

    sprintf(testNum, "%d", i); //converting testNum as int to string
    //adding test num to file dir
    strcpy(fp, file);       //adding strings to make file name
    strcat(fp, testNum);
    strcat(fp, fileEnd);
    printf("%s", fp);

        /* Check for existence */
        if((_access(fp, 0 )) != -1 ){           //Function to check if file exists
            printf( "nFile logs existsn" );
        }
         else { //if file doesnt exists 
          printf("nFile doesnt existn");
          result = i; //set result to equal current value for i
          break;
         }
    }
return result;  //send file num to next function
}


int readPort(HANDLE Comms, int testNum){
//READING DATA FROM SERIAL PORT
//time_t rawtime;
//struct tm * timeinfo;
//time (&rawtime);
//timeinfo = localtime (&rawtime);
char word(14) = "Test Finished";  //Text to look for
char SerialBuffer(256);//Buffer for storing Rxed Data
DWORD NoBytesRead;  //set type for NoBytesRead
char Num(10);
sprintf(Num, "%d", testNum);    //convert test num to string
char str(80);
//char buf(100);
char *file = "C:/Users/jgrayjt/Documents/Logs/TestLog_";
//char tandd(8) = "_%x_%X";
char fileEnd(5) = ".txt";
//strftime(buf,64, "_%x_%X", timeinfo);
strcpy(str, file);      //adding strings to make file name
strcat(str, Num);
//strcat(str, buf);
strcat(str, fileEnd);
printf("%s", str);

FILE *fp;    //create file pointer

fp = fopen(str, "w");   //create file to write serial data to

    do { //start do while loop
        ReadFile(Comms,           //Handle of the Serial port
                 SerialBuffer,       //
                 sizeof(SerialBuffer) -1,//Size of Buffer
                 &NoBytesRead,    //Number of bytes read
                 NULL);

        SerialBuffer(NoBytesRead) = ''; //Specify null terminator to stop data rxing strangly

        printf("%s", SerialBuffer); //Print rx'd data to CMD
        fprintf(fp, "%s", SerialBuffer); //Save rx'd data to txt file


        char *fin = strstr(SerialBuffer, word); //Find 'search' in SerialBuffer and assign to 'fin'

        //if fin has data then close Serial and close/save file
        if (fin != NULL){
            printf("Results Successfully logged n r n r");
            fclose(fp);         //close file
            fp = NULL;          //set file pointer to equal null to break from the loop
        }
    } while (fp != NULL);  //while, from do while loop
return testNum; //return testNum for use in another function
}



void parseFile(int fileNum){
//FUNCTION TO PARSE DATA FROM LOG FILE TO FIND FAILED TESTS

char Num(10);   //set Num as char and give extra memory
sprintf(Num, "%d", fileNum); //Convert filenNum to string
char dir(80);   //set dir as char and give extra memory
char *file = "C:/Users/jgrayjt/Documents/Logs/TestLog_";
char fileEnd(5) = ".txt";
strcpy(dir, file);      //adding strings to make file name
strcat(dir, Num);
strcat(dir, fileEnd);
printf("%s", dir);
FILE *fp1;      //create file pointer
char str(512);  //string to store data read from log file
const char fail(5) = "FAIL";    //text to look for
const char testnum(23) = "Test Iteration";     //text to look for
char *ret;  //create char variables
char *num;

fp1 = fopen(dir , "r");  //Open file to read

    if (fp1 == NULL){ //if you cant open file, print 
        printf("File open fail");
    }

    //Loop to find test number and fail strings  
    while( fgets (str, 512, fp1)!=NULL ) { 
        num = strstr(str, testnum); //find test num in string and assign to num
        ret = strstr(str, fail);    //find 'fail' in string and assign to ret

    if (ret != NULL && num != NULL){    //if both variables have data then print num
        printf("n r %snr", num);  //num has been given enough mem to include the fail that comes after it
    }
    }

fclose(fp1);    //close/save fil
getchar();
getchar();
}

Execution of a shell command when a file is added to FTP under Ubuntu Linux

I have recently implemented a continuous integration pipeline to deploy a .NET Core application on my Linux machine installed in the cloud.

My CI pipeline publishes my application (especially a .NET Web application), zips it, and uploads it by ftp.

Now I have developed the following shell script that I will run as a service.

  • This script is able to detect as soon as a file has been downloaded on
    my FTP folder (/ home / MyName / ftp / files) by residues the vbftp log.

  • The script then stops the service running the actual website.
    application, temporarily putting the site offline.

  • The existing site is then saved.

  • We then unzip the newly downloaded file to the location where the website is located.
    applications lives. (/ var / www / MyProject).

  • The newly downloaded file is deleted and the service restarted.

Below you will find the full contents of the shell script

#!/bin/sh

tail -F /var/log/vsftpd.log | while read line; do
  if echo "$line" | grep -q 'OK UPLOAD:'; then
    filename=$(echo "$line" | cut -d, -f2)
    if ( "$ filename" == "MyProject" ); then
     # Stop site service 
     service MyProject stop 
     # Make backup of existing files 
     sudo zip -r /var/backups/site/$(date +%F)_MyProject /var/www/MyProject 
     # unzip the newly received files 
     # (-o to overwrite only the files which have changed) 
     sudo unzip -o /home/MyName/ftp/files/MyProject.zip -d /var/www/MyProject
     # Remove uploaded zip  
     sudo rm /home/MyName/ftp/files/MyProject.zip 
     #Restart service 
     service MyProject start 
  fi
done

I am a bit new on linux and shell and would like to have your comments on the script that I have already produced above.

Trade execution – Discussions & Help

For a Forex trader, the execution of the order is very important. There are many brokers who give reqoute by placing an order on their platform. It's the most irritated thing in trading. In my previous broker, I had the habit of dealing with this problem. Then I decided to change broker. Currently, I am trading with a XeroMarkets broker. Now, I'm happy with their commercial execution. It executes transactions instantly without re-querying.

Sharepoint online – Script execution for pages without a header

Did sharepoint simply take script execution for pages that do not follow the standard header? All my blank pages like this one worked before and now all my users can not use them anymore. It's as if it's happening without me knowing why or what has changed, which is bad enough for me, unfortunately, because we have developed all access to the files by channeling them.

: / And now I have to fix it in one day ….

trees – How to find the method of division and conquest of complexity at the time of execution without the main theorem

I understand that the main theorem can be used to solve divide and conquer analysis times if they come in the form: $ T (n) = aT ( frac {n} {b}) + n ^ obstruction ^ k (n) $ The reason behind this is to draw a tree of subroutines and see how each k level behaves, right?

Suppose now that your divide and conquer algorithm can be described as follows:

$ T (n) = T ( frac {n} {2}) + 1.5 ^ n $

I guess it's $ theta (1.5 ^ n) $ simply because it seems that this term dominates, but my hypothesis is not logical. How would you find great theta at this task?

My attempt to find the answer was to draw the first levels of the tree by looking for:

Level 1: $ T (n) = 1.5 ^ n $

Level 2: $ T (n) = 1.5 ^ { frac {n} {2}} $

Level 3: $ T (n) = 1.5 ^ { frac {n} {4}} $

So it seems that for level k (from 1), the task turns out to be 1.5 $ ^ { frac {n} {2 ^ {k-1}}} $

So, as the number of levels increases, it seems that the time required to complete the task decreases by a factor of 2?

Any help is welcome! Tips are preferable, but if you want to provide the complete answer, that's fine too.

Computer Architecture: Execution in the Mess – Load / Save

In out-of-service execution, what happens if there is a younger shop that runs before an older load. Will the charge not receive the wrong data if the youngest store writes to the same address?
I understand the problem of homonymy of memory that is to say when the younger load depends on the old store which is the flip side of my question.

Example: –
Older A: load R1 <- R0(8) Younger B : Store R2 -> R3 (25)

The case is as follows: if B executes before A with R3 (25) = R0 (8) (the store writes to the address and loads later instr gets the new data if their execution is incorrect !!). How is this business managed?